In many situaltion, when you are working on number calculation or any other operation related to number and value assigned to variable is not valid number. In such situation your code will thrown an error. To avoid such instances you have to check whether variable value or assigned value is legal number or not.
Javascript isNaN
function is used to determines whether value is a legal number or not. Javascript isNaN
function is used with Number object.
Note: Javascript Number object hase NaN property which can be used to assign a variable with 'not a number' value.
Syntax
isNan(0);
isNan('isNan');
isNan(-1.895);
<!DOCTYPE html>
<html>
<head> <!-- www.techstrikers.com -->
<title>My first Javascript code</title>
</head>
<body bgcolor="#bnde45">
<fieldset>
<legend>Javascript isNaN Function</legend>
<script>
document.write(isNaN(0));
document.write("</br>");
document.write(isNaN("isNan"));
document.write("</br>");
document.write(isNaN(-1.891));
document.write("</br>");
document.write(isNaN("12"));
document.write("</br>");
document.write(isNaN("2015/4/8"));
</script>
</fieldset>
</body>
</html>