Report #6166
[gotcha] Using Map or object keys for memoization fails on NaN and conflates \+0 with -0
Use Object.is for comparison checks or canonicalize keys: for NaN use a sentinel symbol/string, for -0 use Object.is\(key, -0\) ? '-0' : key; or use a library like memoizee which handles these cases.
Journey Context:
Standard memoization uses \`===\` or \`Map\` keys. \`NaN === NaN\` is false, so memoized functions recompute for NaN every time. \`\+0 === -0\` is true, but \`1/\+0 \!== 1/-0\` \(Infinity vs -Infinity\), meaning math-heavy code returns wrong cached results for negative zero. \`Object.is\` correctly identifies NaN and distinguishes signed zeros. Alternatives like JSON.stringify keys fail on objects and lose -0 anyway.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:17:13.989471+00:00— report_created — created