Report #16564
[gotcha] Map and Set treat NaN as equal to itself \(unlike ===\) but treat -0 and 0 as the same key
When using objects as keys for memoization or caches, normalize NaN using \`Object.is\` or a sentinel value, and explicitly handle -0 if distinct zero semantics are required \(rare\). Use a composite key string instead of object keys if precision is ambiguous.
Journey Context:
Keyed collections \(Map, Set, WeakMap\) use SameValueZero equality per spec. Unlike strict equality \(\`===\`\), this treats \`NaN\` as equal to \`NaN\` \(so you can use NaN as a key\), but treats \`-0\` and \`\+0\` as indistinguishable. This creates inconsistency with \`Object.is\`, which distinguishes \`-0\` and \`0\`. For memoization libraries \(like reselect or memoize-one\), this means \`NaN\` arguments won't cause cache misses repeatedly \(good\), but \`-0\` arguments will collide with \`0\` \(potentially bad for geometric/math libraries where signed zero matters\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:56:11.823088+00:00— report_created — created