How to check NaN property in javascript
NaN
stands for "Not a Number". To check if object is NaN
you cannot use != or == comparison. NaN is not a Number or String.
You have to use isNaN()
function or !NaN
.
x = parseFloat('1234.5');
y = parseFloat('abc');
alert(x); //1234.5
alert(y); //NaN
alert(x == false); //false
alert(y == false); //false
alert(x == true); //false
alert(y == true); //false
alert(!x); //false
alert(!y); //true - it works!
alert(typeof(y)); //number
alert(y == NaN); //false
alert(y == 'NaN'); //false
alert(isNaN(y)); //true - it works!