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.
Description
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 since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |
Number.isNaN()
is not supported in Internet Explorer.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.