JavaScript isNaN (VAR) function, returns a Boolean value
Used to determine if VAR is a non-numeric value, if the Non-numeric value returns True, or False if it is not.
Cases:
var intnum = 4;
var floatnum = 3.1415;
var str1 = "I am a student";
var obj= window;
isNaN (Intnum) returns false
isNaN (Floatnum) returns false
isNaN (STR1) returns True
isNaN (obj) returns true
Intnum,floatnum are numbers, so returns false, and STR1 is a string, obj is an object, so returns true;
var intstr = "1234";
var floatstr = "3.1315";
var str2 = "3a";
var str3 = "3.1415a";
isNaN (INTSTR) returns false
isNaN (FLOATSTR) returns false
isNaN (STR2) returns True
isNaN (STR3) returns True
Here Intstr,floatstr though is a string, but intstr,floatstr are numeric strings that can be converted to numbers, so return
False, and STR2,STR3 can neither be converted from integers nor converted by floating-point numbers, so return true
How to use:
< HTML >
< head >
< title > isNaN usage </title >
< BODY >
< font color = "Red" >
< script type = "Text/javascript" > ...
<!--
var intnum = 4;
var floatnum = 3.1415;
var str1 = "I am a student";
var obj= window;
document.write (isNaN (intnum) + "<br>");//return False
document.write (isNaN (floatnum) + "<br>"); return False
document.write (isNaN (str1) + "<br>");//return True
document.write (isNaN (obj) + "<br>");//return True
var intstr = "1234";
var floatstr = "3.1315";
var str2 = "3a";
var str3 = "3.1415a";
document.write (isNaN (INTSTR) + "<br>");//return False
document.write (isNaN (FLOATSTR) + "<br>");//return False
document.write (isNaN (str2) + "<br>");//return True
document.write (isNaN (STR3) + "<br>");//return True
-->
</script >
</font >
</Body >
</HTML >