JavaScript .isNaN()

Anonymous contributor's avatar
Anonymous contributor
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.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

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

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours