JavaScript isNaN()Function
Definition and Usage
The isNaN() function is used to check whether its argument is a non-numeric value.
It returns true if the argument value is NaN or a non-numeric value such as a string, object, undefined, etc.; otherwise, it returns false.
Syntax
isNaN(value)
| Parameter | Description |
|---|---|
| value | Required. The value to be tested. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the isNaN() function.
Example
Example
Check if a number is illegal:
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>");
The output of the above example:
false
false
false
false
true
true
false
false
false
true
true
Try it yourself »
Other Extensions
JavaScript Global Functions