Skip to content
JavaScript·Intermediate·Output based·1 min read

Why does NaN === NaN evaluate to false?

Short interview answer

By IEEE 754 floating-point specification, NaN is defined to not equal itself under any equality comparison, strict or loose. Number.isNaN() or Object.is() must be used to correctly detect a NaN value.

Example

JavaScript
NaN === NaN;          // falseNumber.isNaN(NaN);    // true[1, NaN].includes(NaN); // true  — includes uses SameValueZero[1, NaN].indexOf(NaN);  // -1    — indexOf uses ===

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Equality and type coercion

Related questions