Number.isNaN()

Checks whether a value is exactly NaN.

Returns
true or false.
On this page

Example

#
JavaScript
const age = Number('twenty')

console.log(age)
console.log(Number.isNaN(age))
console.log(age === NaN)
console.log(Number.isNaN('abc'))
console.log(isNaN('abc'))
Console
NaN
true
false
false
true

Definition and usage

#

The Number.isNaN() function returns true only when the given value is the number NaN (Not a Number). NaN shows up, for example, after a failed conversion from text to a number, or after dividing 0 / 0.

You can’t check this with a comparison, because NaN is the only value in JavaScript that isn’t equal to itself: NaN === NaN returns false.

The older, global isNaN() function first converts its argument to a number, so it also returns true for ordinary strings like "abc". Number.isNaN() doesn’t do that and is more predictable.

Syntax

#
Syntax
Number.isNaN(value)

Parameters

#
  • value

    any value

    The value being checked.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • After every conversion from text to a number, check the result with Number.isNaN().
  • Avoid the global isNaN(), since it silently converts types.

Related entries

#

Spotted a mistake or missing an example? Write to us.