I just happen to stumble upon a code which checks the typeof
of a varable passed to it just like this.
function myNaN(b){
if(typeof(b) == 'number'){
// execute some code
}
}
Whenever I call this function it works fine and passes the if condition if number is being passed.
However when I pass a NaN
(which is the output of some other function) to this function the if
condition returns true.
My question is it correct that typeof(NaN) == 'number'
? If so, why? Isn't it confusing?
Just try running console.log(typeof(NaN));
in browser console to see what I mean.