English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript Global Properties/Function
GlobalNaNThe property represents 'Not'-A-The value of 'Number' (not a number).
For example, if you try to multiply a number by a string, the returned value is 'NaN'.
The initial value of NaN is Not-A-Number, withNumber.NaNof the same value.
UsingisNaN()Function to check if the value is NaN.
NaN
var ans = 10 * 'Hello'; ;document.getElementById('result').innerHTML = ans;Test 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 |
Check if the value is NaN using the isNaN() function:
var str = 'Hello world'; var ans = Number(str); // Convert a string to a number ;if (isNaN(ans)) { ;document.getElementById('result').innerHTML = ans; }Test See‹/›