JavaScript isNaN()
Example
Check if a value is NaN:
isNaN(123);
isNaN(-1.23);
isNaN(5-2);
isNaN(0);
Try it Yourself »
isNaN(-1.23);
isNaN(5-2);
isNaN(0);
isNaN('123');
isNaN('Hello');
isNaN('2005/12/12');
Try it Yourself »
isNaN('Hello');
isNaN('2005/12/12');
More examples below.
Description
In JavaScript NaN
is short for "Not-a-Number".
The isNaN()
method returns true if a value is NaN.
The isNaN()
method converts the value to a number before testing it.
See Also:
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 »
isNaN('Hello');
// This returns false;
Number.isNaN('Hello');
Try it Yourself »
Number.isNaN('Hello');
Syntax
isNaN(value)
Parameters
Parameter
Description
value
Required.
The value to be tested.
The value to be tested.
Return Value
Type
Description
A boolean
true
if the value is NaN, otherwise
false
.
More Examples
Check if a value is NaN:
isNaN(0/0);
isNaN('');
isNaN('A');
isNaN(true);
isNaN(false);
Try it Yourself »
isNaN('');
isNaN('A');
isNaN(true);
isNaN(false);
isNaN('NaN');
isNaN(NaN);
isNaN(undefined);
isNaN(null);
Try it Yourself »
isNaN(NaN);
isNaN(undefined);
isNaN(null);
Browser Support
isNaN()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |