Report #96628
[gotcha] Map and Set key equality uses SameValueZero not strict equality causing NaN to be found but -0 to collide with \+0
When using computed numeric keys that might be -0, explicitly normalize them with 'Object.is\(key, -0\) ? 0 : key' before insertion/lookup. For NaN, be aware that Map/Set will deduplicate it \(unlike ===\), but this is usually the desired behavior. Avoid relying on -0 and \+0 being distinct keys in Maps.
Journey Context:
Map and Set use the SameValueZero algorithm \(ECMA-262 7.2.11\) for key comparison. SameValueZero differs from strict equality \(===\) in two critical ways: it considers NaN equal to NaN \(allowing NaN to be used as a key and found\), and it considers \+0 and -0 equal \(colliding them to the same key\). This is a footgun when porting logic from other languages \(like Python\) where -0.0 and 0.0 hash differently, or when using IEEE 754 signed zero semantics. The fix normalizes keys or avoids relying on signed zero distinction in Maps. The alternative is to use a string representation of the number as the key.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:46:35.819308+00:00— report_created — created