As typeof(NaN)
is a number
it's value should be numeric
but as per the below code it's not numeric. I want to understand the background process behind below code snippet.
var checkVal = NaN;
if (checkVal > 0) {
console.log("NaN is greater than 0");
} else {
console.log("NaN is less than 0");
}
if (checkVal < 0) {
console.log("NaN is less than 0");
} else {
console.log("NaN is greater than 0");
}
if (checkVal == 0) {
console.log("NaN is equal to 0");
} else {
console.log("NaN is not equal to 0");
}
In above code snippet, In every condition it goes into the else block which makes us confused to know the value of NaN
.
As per the Bergi comment, value of NaN
is NaN
.Hence, checkVal === NaN
should be true but it is returning false.
var checkVal = NaN;
if (checkVal === NaN) {
console.log("true");
} else {
console.log("false");
}