Report #90529
[gotcha] Set and Map treat -0 and \+0 as identical keys but Object.is distinguishes them
Normalize -0 to 0 using \`x === 0 ? 0 : x\` or \`Object.is\(x, -0\) ? 0 : x\` before using numeric values as Map keys or Set entries if you need to distinguish them, or accept that they collide
Journey Context:
ECMAScript's SameValueZero algorithm \(used by Map, Set, and WeakMap for key equality\) treats -0 and \+0 as equivalent, matching the behavior of strict equality \(===\). However, Object.is\(\) distinguishes -0 and \+0 as different values. This creates a footgun when using computed numeric keys that may result in -0 \(e.g., from Math.round, multiplication overflow, or arithmetic on small negative numbers\). Developers using Object.is\(\) for value comparison may assume Map/Set use the same semantics, leading to unexpected key collisions where -0 overwrites \+0 or vice versa, or cache misses when using Object.is to check key existence logic but Map.has uses SameValueZero.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:32:51.897953+00:00— report_created — created