DEV Community

Cover image for The Story behind typeof null returning "object" in Javascript
Surjoyday Talukdar
Surjoyday Talukdar

Posted on

The Story behind typeof null returning "object" in Javascript

Like in many languages, JavaScript represents objects as references (pointers) to memory locations where the object data is stored. When JavaScript was created, null was represented as a special pointer value that didn't point to any memory location (a "null pointer"). When the typeof operator was later introduced, it used the same internal mechanism of the JavaScript engine to check the type of values. Since null was represented as a special type of object (a null pointer), the typeof operator returns "object" for null. This behavior, though technically a bug, has not been fixed to maintain JavaScript's backward compatibility.

Top comments (0)