English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript Global Properties/Function
GlobalisNaN()function that determines whether a value is an invalid number (non-numeric).
This function is different from the specificNumber.isNaN()Method.
The global isNaN() function converts the tested value to Number and then tests it.
Number.isNaN()It does not convert the value to Number and will not return true for any non-Number type.
isNaN(value)
isNaN(451); // false isNaN(-3.13); // false isNaN(3-1); // false isNaN(0); // false isNaN("451"); // false isNaN("Hello"); // true isNaN("20/12/2018"); // true isNaN('');// false isNaN(true); // false isNaN(undefined); // true isNaN('NaN'); // true isNaN(NaN); // true isNaN(0 / 0); // trueTest See‹/›
All browsers fully support the isNaN() function:
Function | |||||
isNaN() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
value | Value to be tested |
Return Value: | If the given value is NaN, it returns false; otherwise, it returns true |
---|---|
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‹/›