.isNaN()

Published Oct 7, 2021Updated Oct 12, 2021
Contribute to Docs

The Number.isNaN() method is part of the Number class in JavaScript.

It accepts a single argument, value, and returns true if the passed argument is NaN (“Not a Number”), and returns false, otherwise.

Syntax

Number.isNaN(value);
  • value (required): The value to check.

Example 1

To verify if 0 / 0 is NaN:

const x = 0 / 0;
console.log(Number.isNaN(x));
// Output: true

The square root of a negative number would return NaN, so it would return true.

Example 2

To verify if 5 is NaN:

const y = 5;
console.log(Number.isNaN(y));
// Output: false

It would return false because 5 is a number.

Codebyte Example

Code
Output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy