What does NaN === NaN evaluate to?

The story behind the answer

What does NaN === NaN evaluate to? It evaluates to false.

NaN means “Not a Number,” but in JavaScript it is a special numeric value, not a separate non-number type. The strict equality operator follows ECMAScript’s rule that NaN is not equal to any value, including another NaN. Therefore, NaN === NaN returns false, and NaN == NaN is also false.

This behavior comes from IEEE 754 floating-point rules, where NaN represents an unordered or invalid numeric result. It can arise from operations such as 0 / 0, converting an invalid numeric string with Number(), or taking Math.sqrt(-1). NaN also propagates through many arithmetic operations, so later calculations may remain NaN.

The result creates a classic JavaScript trap: comparing a variable directly with NaN cannot reliably test whether it contains NaN. Use Number.isNaN(value) for a strict check, or Object.is(value, NaN), which returns true for NaN. The global isNaN() function is broader because it first coerces its argument, so Number.isNaN() is usually the safer choice when the value’s type matters.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: