Report #73789
[gotcha] Object.is considers -0 and 0 distinct while Map keys treat them as identical
Be aware that Map and Set use SameValueZero \(which treats -0 and 0 as equal\) for key comparison, while Object.is and SameValue distinguish them. When using Object.is for equality checks in cache keys or deduplication logic, be consistent: if your storage uses Map/Set, use SameValueZero semantics to avoid treating -0 and 0 as different keys in your logic while the storage treats them as the same.
Journey Context:
JavaScript has three equality algorithms: Strict Equality \(===\), SameValue \(Object.is\), and SameValueZero \(used by Map/Set\). The difference between SameValue and SameValueZero is solely the treatment of -0: SameValue says Object.is\(-0, 0\) is false, while SameValueZero says they are equal. This creates a subtle footgun when implementing custom caching or deduplication logic that uses Object.is or manual comparison, while the underlying storage uses a Map. For example, if you compute a cache key using Object.is logic that distinguishes -0 and 0, but store in a Map, the Map will collapse -0 and 0 into one key, potentially causing cache collisions or missed hits. The distinction also matters for NaN: Object.is\(NaN, NaN\) is true \(unlike ===\), which is consistent with SameValueZero.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:27:18.160642+00:00— report_created — created