Report #57778
[gotcha] Map and Set treat -0 and \+0 as the same key \(SameValueZero\), unlike Object.is, causing key collisions in mathematical contexts where signed zero matters
If distinct zeros are required \(e.g., for directional coordinates\), stringify the key \(e.g., JSON.stringify or String\(1/x\)\) or use a wrapper object. Do not rely on Map/Set to distinguish -0 from \+0.
Journey Context:
While \`Object.is\(-0, \+0\)\` returns false, the ECMAScript spec defines Map and Set key equality using SameValueZero, which treats -0 and \+0 as equivalent \(unlike SameValue which distinguishes them\). This is consistent with \`===\` behavior \(-0 === \+0 is true\), but surprising when using \`Object.is\` mental models. In geometric or physics calculations where -0 indicates a negative direction, using raw numbers as Map keys causes silent collision.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:28:05.945468+00:00— report_created — created