whytypeof null
As a result of theObject
?
Null is a basic data type and is stored on the stack; The result of typeof NULL is Object, which is a reference data type stored in the heap. Second, if alert (Person instance of Object) returns false, we know that null is not an instance of Object.
whytypeof null
As a result of theObject
?
Simply put, the reason typeof null results in Object is a bug. In the original version of javascript, the 32-bit system used by JS used low bits to store variable type information for performance optimization.
The data type | Machine code identification |
---|---|
Object (Object) | 000 |
The integer | 1 |
Floating point Numbers | 010 |
string | 100 |
Boolean | 110 |
undefined |
Minus 2^31. |
null |
Full of 0 |
When determining the data type, it is judged by the machine code low level identifier, and the null machine code low level identifier is all zeros and the object machine code low level identifier is 000. So the result of typeof NULL is misinterpreted as Object.