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

JavascriptWeb DevelopmentFront End Technology

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.


raja
Published on 17-Jan-2018 16:21:34
Advertisements