Number.isNaN()
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.
TheNumber.isNaN()
static method determines whether the passed value is the number valueNaN
, and returnsfalse
if the input is not of the Number type. It is a more robust version of the original, globalisNaN()
function.
Try it
function typeOfNaN(x) { if (Number.isNaN(x)) { return "Number NaN"; } if (isNaN(x)) { return "NaN"; }}console.log(typeOfNaN("100F"));// Expected output: "NaN"console.log(typeOfNaN(NaN));// Expected output: "Number NaN"
Syntax
Number.isNaN(value)
Parameters
Return value
The boolean valuetrue
if the given value is a number with valueNaN
. Otherwise,false
.
Description
The functionNumber.isNaN()
provides a convenient way to check for equality withNaN
. Note that you cannot test for equality withNaN
using either the==
or===
operators, because unlike all other value comparisons in JavaScript, these evaluate tofalse
whenever one operand isNaN
, even if the other operand is alsoNaN
.
Sincex !== x
is only true forNaN
among all possible JavaScript values,Number.isNaN(x)
can also be replaced with a test forx !== x
, despite the latter being less readable.
As opposed to the globalisNaN()
function, theNumber.isNaN()
method doesn't force-convert the parameter to a number. This makes it safe to pass values that would normally convert toNaN
but aren't actually the same value asNaN
. This also means that only values of the Number type that are alsoNaN
returntrue
.
Examples
Using isNaN()
Number.isNaN(NaN); // trueNumber.isNaN(Number.NaN); // trueNumber.isNaN(0 / 0); // trueNumber.isNaN(37); // false
Difference between Number.isNaN() and global isNaN()
Number.isNaN()
doesn't attempt to convert the parameter to a number, so non-numbers always returnfalse
. The following are allfalse
:
Number.isNaN("NaN");Number.isNaN(undefined);Number.isNaN({});Number.isNaN("blabla");Number.isNaN(true);Number.isNaN(null);Number.isNaN("37");Number.isNaN("37.37");Number.isNaN("");Number.isNaN(" ");
The globalisNaN()
coerces its parameter to a number:
isNaN("NaN"); // trueisNaN(undefined); // trueisNaN({}); // trueisNaN("blabla"); // trueisNaN(true); // false, this is coerced to 1isNaN(null); // false, this is coerced to 0isNaN("37"); // false, this is coerced to 37isNaN("37.37"); // false, this is coerced to 37.37isNaN(""); // false, this is coerced to 0isNaN(" "); // false, this is coerced to 0
Specifications
Specification |
---|
ECMAScript® 2026 Language Specification # sec-number.isnan |