Latest web development tutorials

JavaScript isNaN () function

Function Reference Manual JavaScript Global Functions

Definition and Usage

isNaN () function is used to check whether the parameters are non-numeric.

If this parameter is non-numeric or string value NaN, the object, undefined and other returns true, otherwise it returns false.

grammar

isNaN(value)

参数 描述
value 必需。要检测的值。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support isNaN () function


Examples

Examples

Check whether a number is illegal:

<script>

document.write(isNaN(123)+ "<br>");
document.write(isNaN(-1.23)+ "<br>");
document.write(isNaN(5-2)+ "<br>");
document.write(isNaN(0)+ "<br>");
document.write(isNaN("Hello")+ "<br>");
document.write(isNaN("2005/12/12")+ "<br>");

</script>

Examples of the above output:

false
false
false
false
true
true

try it"


Function Reference Manual JavaScript Global Functions