I have written below code in JS.
function foo() {
var s = "Jack";
s = parseInt(s);
console.log(s)
if (s!=NaN) {
if (typeof (s) == "number")
console.log("number");
else if (typeof (s) == "string")
console.log("string");
} else {
console.log("Your entry is not a number");
}
}
As i am trying to parseInt a string, i got NaN as value.
We know that typeof(NaN) is "number" and numbers can be compared directly like(1==1) in IF condition. But this didn't work.
I tried with isNaN(s) and it worked where as s!=NaN failed.
why ?