Report #10152
[gotcha] Array indexOf returns -1 for NaN but includes returns true
Use Array.prototype.includes for existence checks when NaN is possible, or use Object.is for comparisons. Avoid indexOf for NaN detection.
Journey Context:
The Strict Equality Comparison algorithm \(===\) used by indexOf specifies that NaN \!== NaN. However, Array.prototype.includes uses the SameValueZero algorithm, which treats NaN === NaN \(like Object.is\) but treats \+0 and -0 as equal. This inconsistency exists because TC39 added includes later and chose SameValueZero for consistency with Map/Set key semantics. Developers often assume includes is syntactic sugar for indexOf \!== -1, leading to false negatives for NaN searches in validation logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:54:13.653460+00:00— report_created — created