Why JavaScript 'var null' throw an error but 'var undefined' doesn't?


The web browser throws an error for “var null” because it is a reserved identifier.

You cannot use the following literals as identifiers in ECMAScript −

null
frue
false

undefined 

A property with no definition. It is not known and not a reserved identifier. Its type is undefined.

null

It is known and a reserved identifier. But “null” isn’t the same as “false”. When you will declare a variable and set it to null, then null will get printed.


Updated on: 13-Jun-2020

84 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements