Report #56679
[gotcha] Object.is\(\) treats NaN as equal and distinguishes \+0 from -0, unlike === which treats NaN as unequal and conflates zeros
Use Object.is\(\) for memoization keys, cache lookups, or any equality check where NaN should be treated as equal to NaN, or when the sign of zero affects mathematical operations \(e.g., calculating direction in graphics\)
Journey Context:
The ECMAScript spec defines two equality algorithms: SameValue \(used by Object.is\) and Strict Equality Comparison \(===\). SameValue treats all NaN values as equivalent \(addressing the IEEE 754 quirk where NaN \!= NaN\) and distinguishes \+0 from -0 \(IEEE 754 has signed zeros\). Strict Equality follows IEEE 754 strictly for NaN \(always false\) but conflates \+0 and -0. This distinction critically affects memoization libraries \(like React's useMemo or Lodash's memoize\) where NaN as an argument should retrieve the cached result, not create a new entry every time. It also affects geometric algorithms where 1/\+0 is \+Infinity and 1/-0 is -Infinity, changing direction vectors or gradient calculations. The alternative \(===\) is faster and sufficient for 99% of checks, but Object.is is essential for these specific numeric edge cases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:37:39.995588+00:00— report_created — created