Unreserved Identifiers in Java Script

JavaScript contains about 44 identifiers that are reserved for keywords, but Infinity, NaN, and undefined are classified as non-reserved identifiers in JavaScript. Why are they called identifiers and why are they not reserved?

+6
source share
1 answer

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

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

NaN is a property of a global object.

The initial value of NaN is Not-A-Number - the same as the value of Number.NaN. In modern browsers, NaN is an unconfigurable, unprivileged property. Even if it is not, avoid overriding it.

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

undefined is a property of a global object, i.e. is a variable in a global area.

The initial value of undefined is the primitive value of undefined.

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

Infinity is a property of a global object, i.e. is a variable in a global area.

The initial value for Infinity is Number.POSITIVE_INFINITY. The value of Infinity (positive infinity) is greater than any other number, including itself. This value behaves mathematically as infinity; for example, any positive number multiplied by Infinity is Infinity, and everything 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 undefined value is undefined (see 8.1). This property has the attributes {[[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false}.

You may have noticed [[Writable]]: false. In new browsers, assigning a new undefined value has no effect:

 > undefined = 'foo' < "foo" > undefined < undefined 
+6
source

Source: https://habr.com/ru/post/970146/


All Articles