When null Pretends to Be an Object
An exploration of why typeof null returns "object", tracing the behavior back to JavaScriptâs early implementation and the legacy decisions that still shape the language today.
Thereâs a moment in learning JavaScript where something small breaks your mental model.
You write:
typeof nullAnd JavaScript calmly replies:
"object"At first, it feels like you misunderstood something. Maybe null is an object? Maybe thereâs some hidden structure behind it?
But the truth is much simplerâand stranger.
Itâs a mistake.
null Was Meant to Mean âNothingâ
Conceptually, null represents the absence of a value.
Itâs JavaScriptâs way of saying:
âThis variable intentionally points to nothing.â
So if you think in terms of meaning:
null â no valueIt is not an object. It doesnât contain properties. It doesnât behave like {}.
Itâs just⌠empty.
So Why Does typeof null Return "object"?
To understand this, we need to go back to the early days of JavaScript.
In its first implementation, JavaScript represented values internally using a system of type tags. Each value stored in memory had a small identifier that told the engine what kind of value it was.
Objects were tagged in a particular way, often using a bit pattern like:
000Unfortunately, null was represented as a null pointer, which also ended up looking like:
000So when the engine checked the type tag, it couldnât distinguish between:
- an actual object
- the
nullvalue
And it reported both as:
"object"Why This Was Never Fixed
At this point, you might wonder:
âWhy not just fix it?â
The problem is that JavaScript became widely used very quickly. By the time this behavior was recognized as a mistake, real-world code already depended on it.
Changing it would break existing applications.
So the language kept the behavior.
What started as a low-level implementation detail became a permanent part of JavaScript.
A Language Shaped by History
This is one of the clearest examples of how JavaScript is shaped not just by design decisions, but by historical constraints.
Unlike newer languages that can refine their type systems over time, JavaScript must remain compatible with decades of existing code.
So instead of being corrected, this behavior was effectively âlocked in.â
What This Means in Practice
Because of this quirk, typeof is not always reliable for distinguishing values.
For example:
typeof {} // "object"
typeof [] // "object"
typeof null // "object"These three values are completely different in meaning, but typeof groups them together.
So if you need to specifically check for null, you should do:
value === nullRather than relying on typeof.
A Small Window Into JavaScriptâs Internals
This behavior might feel like a flaw, but it also reveals something deeper.
JavaScript is not a perfectly clean system built from scratch. Itâs a language that evolved under real-world constraints, carrying decisions made in its earliest days.
The fact that typeof null === "object" is not just a quirk to memorize. Itâs a reminder that behind the syntax and abstractions, thereâs an implementation history shaping everything.
And sometimes, that history leaks through in surprising ways.