Is null a dataType in Javascript?

RMAG news

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

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.

Please follow and like us:
Pin Share