Report #12595
[gotcha] Map and Set use SameValueZero equality where -0 and \+0 are considered the same key but NaN equals NaN
Normalize -0 to \+0 using \`key === 0 ? 0 : key\` before Map operations if you must distinguish signed zeros \(rare\), or accept that all zeros are identical keys; for NaN, leverage the fact it can be used as a valid key \(unlike with plain objects\)
Journey Context:
Map and Set determine key equality using 'SameValueZero', which is almost identical to \`Object.is\` with one critical difference: SameValueZero treats -0 and \+0 as equal, whereas \`Object.is\(-0, \+0\)\` returns false. This creates an asymmetry where Map keys behave differently from strict equality checks for signed zero. This bites in mathematical code where -0 is a meaningful sentinel \(e.g., representing approach from the negative side\) or when using computed keys that result from arithmetic operations like \`Math.min\(0, -0\)\` \(which returns -0\). When such a value is used as a Map key, it overwrites any existing entry keyed by \+0, causing silent data loss. The NaN behavior \(where NaN equals NaN in Map\) is actually a feature compared to plain objects \(where all NaN values are distinct keys in practice, or rather NaN is not a valid object key\), but the -0 quirk is the true footgun. The fix requires explicit normalization of zero values if signed zero distinction is required, though in most cases developers should simply be aware that Map/Set treat all zeros as identical.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:22:37.777915+00:00— report_created — created