Why typeof null === 'object' — And Why JavaScript Still Hasn’t Fixed It


A 25-year-old bug that still fools millions of developers.
🧠 The Confusing Line of Code
If you've ever typed this into your console:
console.log(typeof null); // "object"
You probably paused for a second.
Wait... isn’t
null
supposed to mean nothing? Then why does JavaScript think it's an object?
You're not alone — I had the exact same confusion when I first saw this. And it turns out, this isn’t just a quirk — it’s actually a mistake from JavaScript’s early days that never got fixed.
The First Time I Hit This
I was debugging a function that checks for objects before doing a deep clone. It failed when the input was null
, even though I had used:
if (typeof input === "object") {
// clone logic here
}
But null
slipped right through.
That was the first time I seriously looked into this behavior
So… Why Does typeof null
Return "object"?
Here’s what I learned.
Back in the early days of JavaScript (mid-90s), values were stored in a way where the type information was encoded in binary bits.
Objects had a type tag of
0
.null
was represented as a pointer with a0
value.So when JavaScript ran
typeof null
, it saw the type tag0
, assumed it was an object, and returned"object"
.
Brendan Eich (JavaScript’s creator) admitted this was a bug — But by the time it was discovered, the language was already being used across the web.
Fixing it would have broken thousands (now millions) of websites. So the bug stayed.
Why This Still Causes Real Problems
It’s easy to brush this off as "just one weird edge case," but it actually causes subtle bugs in real code — especially in:
form validations
type checks
data parsing
cloning logic
Example :
const value = null;
if (typeof value === "object") {
// People wrongly assume it must be a real object
}
This fails if value
is null
.
A safer version would be:
function isObject(value) {
return value !== null && typeof value === "object";
}
Knowing this saves time and frustration — and honestly, it’s one of those interview landmines too.
How I Handle It Now
Any time I’m checking for object types, I pause and ask:
Could
null
ever be passed here?Do I need to filter it out before continuing?
It’s one extra step, but it avoids bugs that are hard to trace later.
And once you know about this quirk, it becomes part of your mental model of JavaScript — a reminder that some things in the language exist not because they’re ideal, but because the web depends on them.
🧠 TL;DR Takeaway
typeof null === "object"
is a bug, not a feature.It’s stayed alive for web backward compatibility.
Always check for
null
explicitly when working with objects.Knowing this gives you an edge — especially in interviews.
🧩 Try It Yourself
Pop this in your console:
console.log(typeof {}); // "object"
console.log(typeof null); // "object"
console.log(null instanceof Object); // false
Sneaky, right?
Thanks for reading. If you found this useful, I’m writing more dev-friendly, beginner-first articles that explore common JavaScript quirks and real-world MERN stack lessons. Follow along on hashnode or connect on LinkedIn.
Subscribe to my newsletter
Read articles from Dhruv Burada directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
