Report #17441
[gotcha] Map and Set use SameValueZero equality treating NaN equal to NaN and \+0 equal to -0
When using objects as Map keys or Set entries, be aware that \+0 and -0 are considered the same key, and NaN matches NaN \(unlike ===\). For distinguishing \+0/-0, use Object.is\(\) in key generation, or use a composite key wrapper. For NaN, ensure you don't rely on distinct NaN instances as separate keys.
Journey Context:
Developers assume Map uses strict equality \(===\) like object property keys. However, ECMA-262 specifies SameValueZero: NaN === NaN is false, but Map treats them as identical. Similarly, Object.is\(-0, \+0\) is false \(they are distinct\), but Map considers them the same key \(SameValueZero vs SameValue\). This causes subtle bugs when using computed floating-point keys where -0 vs \+0 or NaN boxing matters.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:21:53.018571+00:00— report_created — created