Report #83819
[gotcha] Map and Set use SameValueZero comparison making NaN equal to NaN but distinguishing \+0 from -0
Rely on Map/Set for NaN keys \(they work as expected\), but use Object.is\(\) or careful checks if you need to manually compare keys including distinguishing \+0/-0 or handling NaN
Journey Context:
Map and Set use SameValueZero algorithm \(ECMA-262 7.2.11\): NaN equals NaN \(unlike ===\), but \+0 and -0 are treated as equal \(unlike Object.is\). This is generally helpful for NaN keys but can be surprising when manually checking key existence or implementing custom Map-like structures. The pitfall is assuming === behavior applies to Map keys, causing missed NaN lookups or incorrect \+0/-0 handling in algorithms relying on distinct keys.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:16:37.626517+00:00— report_created — created