Why typeof null Returns “object” in JavaScript: Explained with History & Real Reasons

Did you know one of JavaScript’s oldest bugs is still alive after nearly 30 years?
The infamous typeof null === “object” continues to confuse developers worldwide — even though it is technically wrong.

If you’ve ever checked the type of null in JavaScript, you might’ve been shocked to see:

typeof null; // "object"

This behavior is one of JavaScript’s longest‑standing quirks, and despite being widely recognized as a bug, it remains unchanged in the language.
In this blog, we’ll break down exactly why this happens, how it originated, and why it still hasn’t been fixed today.

What Is null in JavaScript?

In JavaScript, null is a primitive value.
It represents the intentional absence of any object value.

The ECMAScript specification classifies null as a primitive, just like:

  • string
  • number
  • boolean
  • undefined
  • symbol
  • bigint

So naturally, you’d expect:

typeof null === "null"

But JavaScript gives us “object” instead.
Why? The answer lies deep in JavaScript’s early history.

The Real Reason: A Bug from 1995

When JavaScript was created in 1995, memory was stored in a very different way.

➤ Objects were represented internally using a tag system.

Values had type tags in the first few bits of their binary memory.

➤ The type tag for objects was “000”.

Now here’s the twist:

🔥 null’s memory representation was also all zeroes.

That means:

JavaScript could not distinguish null from an object in its early implementation.

So the interpreter simply returned “object” — even though null is NOT an object.

This was later documented in the ECMAScript spec as a known error.

Then Why Not Fix It?

This is the most important part — and the reason this behavior still exists in 2026.

Fixing it would break the entire web.

Billions of lines of JavaScript rely on typeof null === “object” either directly or indirectly.

Changing the result now would:

  • Break old websites
  • Break dependencies and frameworks
  • Break JSON parsers, polyfills, and libraries
  • Cause unpredictable errors

📌 The ECMAScript Committee (TC39) confirmed that this bug is “unfixable.”

It has become a permanent quirk to maintain backward compatibility.

How to Correctly Check for null

Since typeof can’t be trusted for null, the proper way is:

value === null

or with safety:

value === null && typeof value === "object"

Many developers also use:

value == null // true for null or undefined

Modern frameworks rely on stricter checks to avoid JS quirks like this.

Modern Alternatives to Avoid Confusion

✔️ Use === instead of typeof

if (value === null) { ... }

✔️ Optional Chaining (ES2020)

user?.profile?.name

✔️ Nullish Coalescing

value ?? "default"

JavaScript has evolved a lot, but the language keeps the old behavior unchanged to preserve stability.

Conclusion

The fact that typeof null returns “object” is not just a bug — it’s a historic artifact from JavaScript’s early days.
Although technically incorrect, this behavior has become deeply embedded in millions of applications, making it impossible to fix without breaking the internet.

Understanding this quirk helps developers write safer, cleaner checks and avoid unexpected errors.

👉 If you liked this explanation, share it or comment with another JavaScript quirk you’d like decoded!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top