JavaScript Number isNaN()
Examples
Check if a value is Number.NaN:
Number.isNaN(123);
Number.isNaN(-1.23);
Number.isNaN('123');
Number.isNaN(0/0);
Try it Yourself »
Number.isNaN(5-2);
Number.isNaN(0);
Number.isNaN('Hello');
Number.isNaN('2005/12/12');
Number.isNaN(' ');
Try it Yourself »
More examples below.
Definition and Usage
In JavaScript, NaN
is short for "Not-a-Number".
In JavaScript, NaN
is a number that is not a legal number.
The Number.isNaN()
method returns true
if the value is NaN
, and the type is a Number.
Difference Between isnan() and Number.isnan()
isNaN()
method returns true
if a value is Not-a-Number.
Number.isNaN()
returns true
if a number is Not-a-Number.
In other words:
isNaN()
converts the value to a number before testing it.
Examples
// This returns true;
isNaN('Hello');
Try it Yourself »
// This returns false;
Number.isNaN('Hello');
Try it Yourself »
Syntax
Number.isNaN(value)
Parameters
Parameter | Description |
value | Required. The value to be tested. |
Return Value
Type | Description |
A boolean. | true if the value is Number.NaN,
otherwise false . |
More Examples
Check if a value is Number.NaN:
Number.isNaN(false);
Number.isNaN(true);
Number.isNaN(undefined);
Number.isNaN('NaN');
Number.isNaN(NaN);
Try it Yourself »
Browser Support
Number.isNaN()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Number.isNaN()
is not supported in Internet Explorer 11 (or earlier).