Report #78516
[gotcha] Map and Set treat -0 and \+0 as identical keys despite Object.is\(\) distinguishing them
If distinguishing -0 and \+0 is required \(e.g., mathematical direction\), use string keys \('0' vs '-0'\) or normalize zeros before storage. Be aware Map/Set use SameValueZero equality
Journey Context:
Map and Set use SameValueZero for key equality. SameValueZero differs from Object.is\(\) in exactly one aspect: it treats -0 and \+0 as equivalent \(while Object.is returns false for -0 vs \+0\). Both treat all NaN as equal. This surprises developers using signed zeros for floating-point direction tracking or mathematical contexts who expect Object.is semantics. new Map\(\).set\(0, 'pos'\).get\(-0\) returns 'pos', and new Set\(\[0, -0\]\).size is 1. This silent deduplication causes data loss in physics simulations or financial calculations tracking directional zero.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:23:03.754450+00:00— report_created — created