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

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: 2020-06-13T11:42:53+05:30

176 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements