English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript isNaN() Function

 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.

Syntax:

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); // true
Test See‹/›

Browser Compatibility

All browsers fully support the isNaN() function:

Function
isNaN()YesYesYesYesYes

Parameter Value

ParameterDescription
valueValue to be tested

Technical Details

Return Value:If the given value is NaN, it returns false; otherwise, it returns true
JavaScript Version:ECMAScript 1

More Examples

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‹/›

 JavaScript Global Properties/Function