UNDERSTANDING THE TYPEOF NULL ODDITY

Anas Aqeel

Anas Aqeel

· 1 min read
What is the type Of null in JavaScript?

Working out the null type variable in JavaScript.

Especially with null and undefined, it can be hard to determine what kind of data type you are dealing with. Let's have a look at type of . This returns the type of the variable. You can check the type of a variable by entering type of , then either a space followed by the variable in question, or the variable in question in brackets:

output: // unknown object

There is an odd one out, and that is the null type. In the output you can see that typeof null returns object , while in fact, null truly is a primitive and not an object. This is a bug that has been there since forever and now cannot be removed due to backward compatibility problems. Don't worry about this bug, as it won't affect our programs—just be aware of it, since it will go nowhere anytime soon, and it has the potential to break applications.


Anas Aqeel

About Anas Aqeel

I’m currently working Frontend Development having an experience of building Web applications with JavaScript / React-JS / Node-JS and some other cool libraries and frameworks. I’m currently learning web3 technologies such as Solidity, Ether-JS and web3.

Copyright © 2025 Coding Hub. All rights reserved.
Made by Anas-Aqeel
coding~hub