Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Why is typeof null "object" in JavaScript?

Do you know what will be the output of this code?

JavaScript
console.log(typeof null);
Show answer and explanation

The answer is "object".

This is a bug from the very first JavaScript engine, where values were tagged by type and null shared the tag used for objects. Fixing it would break existing websites, so it stays.

To check for null, compare directly: value === null.

Take the full quiz Next question →

More Basics questions

  1. What happens when you reassign a const in JavaScript?
  2. What is the difference between == and === in JavaScript?
  3. What does Array.push() return in JavaScript?
  4. Is a var loop variable accessible after a for loop?
  5. Why does "5" * "2" equal 10 in JavaScript?

Related topics