Why JavaScript thinks null is an object

Open a JavaScript console and ask the language a simple question:
typeof null
// "object"
This is not JavaScript telling you that null is secretly an object. It is a
bug. More precisely, it is an implementation detail from the first JavaScript
engine that leaked into the language, reached millions of web pages, and became
too expensive to correct.
The strange part is not that a bug shipped. The strange part is that we can trace how it happened, watch standards committees try to remove it, and see the web refuse the repair.
Null is not an object
JavaScript has a distinct Null type with exactly one value: null. The
current ECMAScript specification
lists Null among the language’s primitive types, separate from Object.
The same specification later defines the typeof operator with a table. In
that table, Null maps to the string "object".
Those statements are not contradictory in the spec. typeof is simply an
operator with historically defined results; it is not a perfect reflection API
for the specification’s type system. Functions prove the point too. Functions
are objects, but typeof function () {} returns "function".
The operator’s name invites a stronger promise than the language ever made.
The tag that escaped the engine
The original JavaScript implementation, then called Mocha, needed a compact way to store values. A runtime value carried both its data and a small internal tag telling the engine whether that data represented a number, string, object or something else.
The null value was encoded with the same internal tag used for objects. That
made a certain amount of low-level sense: null represented the absence of an
object reference, and its payload was a null pointer. But when the engine
implemented typeof, it inspected the tag and reported "object". There was no
special check to translate the null value into a more truthful answer.
This account comes directly from Brendan Eich’s recollection in JavaScript: The First 20 Years, the language history he wrote with Allen Wirfs-Brock. They call it a “leaky abstraction”: a private storage decision became observable program behaviour.
One popular retelling says the mistake happened because JavaScript was designed
in ten days. That is only partly right. The early value representation came
from that first rush in 1995, but typeof was added in JavaScript 1.1, completed
for Netscape Navigator 3.0 in 1996. The later operator exposed the earlier
shortcut.
Then the bug became the standard
Once Netscape shipped the behaviour, other browser engines had to match it. Web authors could observe it, so compatibility required it; standardisation then wrote the observable reality down.
That sequence matters. Standards did not invent typeof null === "object".
They inherited it.
Today the result is explicit in the normative
algorithm for typeof: Null
returns "object". A modern engine may represent values completely differently
from Mocha. It must still reproduce the old answer because the answer, not the
old bit layout, is now part of JavaScript.
The fossil outlived the machinery that formed it.
JavaScript tried to fix it
The obvious repair has been proposed more than once:
typeof null
// "null"
During work on ECMAScript 4, Brendan Eich discussed fixing it in a new, explicitly selected language version. After that edition collapsed, a similar idea appeared during the Harmony era that led toward ECMAScript 2015. The hope was that new code could opt into corrected semantics without changing old pages.
That versioned future never became JavaScript’s model. The language instead followed the “one JavaScript” principle: new editions should extend the same language rather than split the web into behavioural modes.
The public 2010 standards discussion
captures the proposal while it was still alive. By a 2012 TC39 meeting, the
minutes record the blunt conclusion that typeof could not be changed. The
committee worried that libraries and existing sites would encounter a new
runtime result where they expected the old one.
This is what “break the web” means in practice. It does not require good code
that deliberately treats null as an object. It only requires enough deployed
code whose branching, validation or feature detection changes when a
thirty-year-old string changes.
The correct object check
If you want to know whether a value is a non-null object, say exactly that:
function isObject(value) {
return value !== null && typeof value === 'object';
}
That includes arrays, dates, regular expressions and class instances. It
excludes functions, because typeof gives callable objects their own
"function" result. If your definition of object includes functions, make the
second half explicit:
function isObjectLike(value) {
return value !== null &&
(typeof value === 'object' || typeof value === 'function');
}
For a nullish check, JavaScript’s much-maligned loose equality has one useful, deliberate idiom:
if (value == null) {
// value is null or undefined
}
Nothing else compares loosely equal to null. If that compact convention is
not welcome in your codebase, value === null || value === undefined says the
same thing at greater length.
TypeScript can keep null separate from object types during static analysis,
especially with strictNullChecks. It cannot change the runtime, so compiled
code still receives "object" from typeof null.
A bug with a constituency
Most language bugs are fixed or forgotten. This one became infrastructure. Every implementation reproduces it, the specification mandates it, interview questions teach it, linters recognise the workarounds, and typed supersets build a more accurate model around it.
That makes typeof null less a story about sloppy language design than a story
about the web’s deepest constraint. JavaScript runs code that was published
without an expiry date. A page written for Netscape can still impose a cost on
an engine built three decades later.
You can see the same compromise throughout the language, from automatic semicolon insertion to coercive equality. We collect the designs and the history together in our JavaScript section, because the things developers joke about are often the clearest record of how a platform actually evolved.
null is not an object. But the wrong answer shipped, people built around it,
and compatibility made it permanent. On the web, history is part of the type
system.





