Why
isNaN(undefined) !== Number.isNaN(undefined)
is true.
Why true
console.log(isNaN(undefined)) //is true
But if I add Number.
console.log(Number.isNaN(undefined)) // is false
Why
isNaN(undefined) !== Number.isNaN(undefined)
is true.
Why true
console.log(isNaN(undefined)) //is true
But if I add Number.
console.log(Number.isNaN(undefined)) // is false
The Number.isNaN
function "is a more robust version" of the global isNaN
function. Specifically, the rules for the global isNaN
function are odd and that's why Number.isNaN
is typically preferred. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN#Description.
According to that, isNaN
essentially checks whether your value is not a number, whereas Number.isNaN
checks whether your value is NaN
. Of course, not all nonnumeric values are NaN
- "test"
for example, is not NaN
but is also not a number.
isNaN
and !anything
will always give you Booleans.
parseFloat('27')
gives you the Number 27
.
27
is not false
, even with type conversion.