Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

NaN

The special Not-a-Number value — the result of a failed math operation.

Available since: ES1

Syntax

NaN

Examples

Where NaN comes from:

console.log(Number('abc'));
console.log(0 / 0);
console.log(typeof NaN);

Output:

NaN
NaN
number

NaN is not equal even to itself:

console.log(NaN === NaN);
console.log(Number.isNaN(NaN));

Output:

false
true

Notes

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.

Thanks for reading!

Donate to the site — we work hard for you.