Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

isNaN

Checks whether converting a value to a number gives NaN.

Available since: ES1

Syntax

isNaN(value)

Parameters

ParameterTypeDescription
valueanyA value; it is converted to a number first.

Return value

booleantrue if converting it to a number gives NaN.

Examples

Checking strings:

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

Output:

false
true

Surprising cases caused by conversion:

console.log(isNaN(''));
console.log(isNaN(undefined));

Output:

false
true

Notes

An empty string converts to 0, so isNaN('') is false. To check an actual number, Number.isNaN() is more reliable.

See also

  • Number.isNaN — Checks that a value is NaN, without type conversion.
  • NaN — The special Not-a-Number value — the result of a failed math operation.
  • 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.