4 ms·
typeof null returns "object", but I do not believe it is correct to claim that null "is an object". It is my understanding (maybe a misunderstanding, I will hap
by saurik 13y ago
typeof null returns "object", but I do not believe it is correct to claim that null "is an object". It is my understanding (maybe a misunderstanding, I will happily state) from reading a ton of comments from Brendan Eich in various places that typeof null is "object" for historical reasons involving the way reference types were implemented in the original JavaScript VM.
- inglor 13y agoExactly, if people are interested I'll gladly find the reference to the relevant esdiscuss thread.
- raganwald 13y agoIt is correct to say that typeof(null) returns the string 'object' because of a bug that is now written into the standard to prevent old software from "breaking" if they fixed this. It is not ever correct to say that null in JavaScript is an object. Just ask javaScript itself: Object.getPrototypeOf(null) //=> TypeError: Object.getPrototypeOf called on non-object