JavaScript Number.isNaN()Method
Example
Check whether the parameter is Number.NaN:
Try it Yourself »
Definition and Usage
NaN is an abbreviation for "Not-a-Number", literally translated asNot a Number。
In JavaScript, NaN is an invalid number.
The Number.isNaN() method is used to determine whether the passed value is NaN and to check whether its type is Number. If the value is NaN and the type is Number, it returns true; otherwise, it returns false.
In JavaScript, the most special thing about NaN is that we cannot use the equality operators == and === to determine whether a value is NaN, because both NaN == NaN and NaN === NaN return false. Therefore, there must be a method to determine whether a value is NaN.
Compared with the global function,isNaN()Number.isNaN() does not convert the argument to a number by itself; it returns true only when the argument is a number whose value is NaN.
Number.isNaN(NaN); // true
Number.isNaN(Number.NaN); // true
Number.isNaN(0 / 0) // true
// 下面这几个如果使用全局的 isNaN() 时,会返回 true。
Number.isNaN("NaN"); // false,字符串 "NaN" 不会被隐式转换成数字 NaN。
Number.isNaN(undefined); // false
Number.isNaN({}); // false
Number.isNaN("blabla"); // false
// 下面的都返回 false
Number.isNaN(true);
Number.isNaN(null);
Number.isNaN(37);
Number.isNaN("37");
Number.isNaN("37.37");
Number.isNaN("");
Number.isNaN(" ");
Browser Support
Number.isNaN() is a new feature in ECMAScript6 (ES6).
Basically the latest browser versions support ES6 (JavaScript 2015).
Number.isInteger() is not supported in Internet Explorer 11 and earlier browsers.
| Chrome | Edge | Firefox | Safari | Opera |
| Yes | Yes | Yes | Yes | Yes |
Syntax
Number.isNaN(value)
Parameter Values
| Parameter | Description |
|---|---|
| value | The value to be detected. |
Return Value
| Type | Description |
|---|---|
| Boolean | Returns true if the value is NaN and the type is Number; otherwise, returns false. |
Technical Details
| JavaScript Version: | ECMAScript 6 |
|---|
More Examples
Example
Check whether the parameter is an integer:
Try it Yourself »
JavaScript Number Object