Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Number.isNaN

Checks that a value is NaN, without type conversion.

Available since: ES2015

Syntax

Number.isNaN(value)

Parameters

ParameterTypeDescription
valueanyThe value to check.

Return value

booleantrue only if the value is exactly NaN.

Examples

The result of a failed conversion:

const age = Number('abc');
 
console.log(Number.isNaN(age));

Output:

true

The difference from the global isNaN():

console.log(Number.isNaN('hello'));
console.log(isNaN('hello'));

Output:

false
true

Notes

The comparison value === NaN is always false, even for NaN itself, so a special function is needed. Number.isNaN() is more reliable than the global isNaN(), which converts its argument to a number first.

See also

  • isNaN — Checks whether converting a value to a number gives NaN.
  • NaN — The special Not-a-Number value — the result of a failed math operation.
  • Number.isFinite — Checks that a value is a finite number (not NaN and not Infinity).

Related recipes

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.