BY Simmi Kava
Null and NaN
JavaScript Oddities - Null and NaN
console.log(typeof null) //object
console.log(null instanceof Object) //false
We all know that value null
represents intentional absence of any object value. typeof
would return a string, hence typeof
null
returns object. This is a historical bug (since the first version of JavaScript) and cannot be fixed.
But since null
is absence of value, it implies it cannot be instance of anything, hence instanceof
returns a false
value.
Similarly,
console.log(typeof NaN) //Number
console.log(NaN === NaN) //false
NaN
is a number from data type point of view. NaN
is a special number as specified by IEEE format specification and is not JavaScript language specific. NaN
is never equal to NaN
, as each NaN
is unique unknown number.
BY Simmi Kava
2 Likes1 Save
Like | Comment | Save | Share |
ARCHIVES
2024
2023
2022
2021