NaN (JavaScript)

NaN stands for "Not a Number" and is the value JavaScript returns when a math operation fails to produce a valid number. It is itself of type number.

JavaScript

You get NaN from operations like dividing by a non-numeric string or parsing text that is not a number. Oddly, NaN is not equal to anything, including itself.

Use Number.isNaN() to reliably check for it, since NaN === NaN is false.

Examples

JavaScript

const result = Number("hello");
console.log(result);
console.log(Number.isNaN(result));

Output:

NaN
true

See also

Back to the Dictionary