DEV Community

Maulik Chaudhary
Maulik Chaudhary

Posted on

Is null a dataType in Javascript?

Well only way to check that out is to use typeof for different values.
If you check with all the possibilities, you'll find out that there are eight dataTypes:

number,
bigint,
string,
boolean,
undefined,
object,
symbol,
function

Yes, you might be wondering what about null?
null falls under object dataType:

check yourself by

typeof(null); // object
Enter fullscreen mode Exit fullscreen mode

That’s an officially recognised error in typeof. Definitely, null is not an object. It is a special value with a separate type of its own. The behaviour of typeof is wrong here.

but if you dig deeper, functions are also an object.
So there is nothing right and nothing wrong here, it depends what context and usecase you're targeting.

Top comments (1)

Collapse
 
const_variable profile image
Maulik Chaudhary • Edited

Objects are the non-primitive dataType
All other types are called “primitive” because their values can contain only a single thing, that includes Symbol dataType also.