Report #86436
[gotcha] Map and Set treat \+0 and -0 as identical keys but NaN as distinct from itself in SameValueZero
When using complex objects as Map keys or checking Set membership for numeric values, be aware that Map.prototype.set\(0, val\) and Map.prototype.set\(-0, val\) overwrite the same entry. For NaN, use Map.prototype.has\(NaN\) which correctly returns true if NaN was stored, unlike indexOf. If you need to distinguish \+0 and -0 in a key, encode the sign separately or use Object.is in a serialization step.
Journey Context:
According to the SameValueZero algorithm used by Map and Set, \+0 and -0 are identical \(unlike SameValue used by Object.is\), but NaN is equal to itself \(unlike ===\). This creates inconsistency when developers use Object.is for custom key hashing but rely on native Map behavior. It particularly affects geometric coordinates where -0 has semantic meaning \(e.g., direction\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:40:19.985475+00:00— report_created — created