English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Number.NaNThe property is used to represent non-numeric values.
For example, if you try to multiply a number with a string, the returned value is 'NaN'.
The initial value of Number.NaN is Not-A-Number, and the globalNaNthe value is the same.
UsingNumber.isNaN()a function to check if a value is a NaN value.
Because NaN is a static property of Number, you should always use it asNumber.NaN, rather than using it as an attribute of the created Number object.
Number.NaN
var ans = 10 * 'Hello'; ;document.getElementById('result').innerHTML = ans;Test and see‹/›
All browsers fully support the NaN property:
Property | |||||
NaN | Yes | Yes | Yes | Yes | Yes |
Writable: | None |
---|---|
Enumerable: | None |
Configurable: | None |
JavaScript Version: | ECMAScript 1 |
Use the Number.isNaN() method to check if the value is a NaN value:
var str = 'Hello world'; var ans = Number(str); // Convert a string to a number ;if (Number.isNaN(ans)) { ;document.getElementById('result').innerHTML = ans; }Test and see‹/›