Jyoti Puri
Jyoti Puri

Reputation: 1346

Unreserved Identifiers in Java Script

JavaScript has about 44 identifiers which are reserved keywords but Infinity, NaN and undefined are categorized as unreserved identifiers in JavaScript. Why are they called identifiers and why are they not reserved ?

Upvotes: 7

Views: 189

Answers (1)

Kurt Stolle
Kurt Stolle

Reputation: 332

undefined,NaN and Infinity are actually properties of the global object:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN

NaN is a property of the global object.

The initial value of NaN is Not-A-Number — the same as the value of Number.NaN. In modern browsers, NaN is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined

undefined is a property of the global object, i.e. it is a variable in global scope.

The initial value of undefined is the primitive value undefined.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/infinity

Infinity is a property of the global object, i.e. it is a variable in global scope.

The initial value of Infinity is Number.POSITIVE_INFINITY. The value Infinity (positive infinity) is greater than any other number including itself. This value behaves mathematically like infinity; for example, any positive number multiplied by Infinity is Infinity, and anything divided by Infinity is 0.


Refer to ELS5 Section 15.1.1

15.1.1.1 NaN

The value of NaN is NaN (see 8.5). This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

15.1.1.2 Infinity

The value of Infinity is +∞ (see 8.5). This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

15.1.1.3 undefined

The value of undefined is undefined (see 8.1). This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

You might notice the [[Writable]]: false. In newer browsers, assigning a new value to undefined has no effect:

> undefined = 'foo'
< "foo"
> undefined
< undefined

Upvotes: 8

Related Questions