Report #44925
[gotcha] Map and Set treat all NaN values as identical keys despite NaN \!== NaN
Do not rely on NaN as a unique sentinel key in Maps/Sets; use a sentinel object or a prefixed string key. To check for NaN existence, iterate and use Number.isNaN.
Journey Context:
The SameValueZero algorithm used for Map/Set keys treats all NaN values as identical \(unlike === where NaN \!== NaN\). This means m.set\(NaN, 1\); m.set\(NaN, 2\) overwrites, and m.has\(Number\('nan'\)\) returns true. While helpful for avoiding duplicate NaNs, it violates the expectation that distinct NaN boxes \(e.g., from different calculations\) are unique keys. This breaks caching strategies using NaN as a 'not found' sentinel. The fix avoids NaN keys entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T05:52:22.397671+00:00— report_created — created