NaN
The special Not-a-Number value — the result of a failed math operation.
Available since: ES1
Syntax
NaNExamples
Where NaN comes from:
console.log(Number('abc'));
console.log(0 / 0);
console.log(typeof NaN);Output:
NaN
NaN
numberNaN is not equal even to itself:
console.log(NaN === NaN);
console.log(Number.isNaN(NaN));Output:
false
trueNotes
Any arithmetic with NaN gives NaN again, so one bad value spoils the whole calculation. Check results with Number.isNaN().
See also
- Number.isNaN — Checks that a value is NaN, without type conversion.
- isNaN — Checks whether converting a value to a number gives NaN.
- Number() — Converts a value to a number.
In the tutorial
- Numbers — Numbers in JavaScript — integers and fractions, rounding, the Math object, toFixed and the special values Infinity and NaN.