I've been diving into a project where type safety matters, especially in JavaScript. As I was reviewing the behavior of my variables, I got really confused when I found out that `typeof null` returns 'object'. Did I mess something up, or is this a quirk I should just know about?
4 Answers
c
You're right; this is just one of those quirky behaviors in JavaScript. It's been around since the early days, and there's really nothing you can do about it now because of backward compatibility. You aren't doing anything wrong! Just keep this oddity in mind.
a
It's a good idea to check the documentation for stuff like this. The MDN page on [typeof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) explains why `typeof null` returns 'object'. It's definitely a weird part of JavaScript's history!

Thanks for the tip! I’ll definitely check that out.