Infinity vs Number.POSITIVE_INFINITY

TL;DR

Infinity used to be overwritable; Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY have always been read only.


Infinity is a property of the global object (window is the global object for Javascript run in the browser), whereas Number.POSITIVE_INFINITY is a property of the Number constructor.

Prior to the 5th Edition of ECMAScript, value properties of the global object were able to be overwritten:

Infinity = 123;
Infinity; // 123

The same applies to undefined and NaN, which are also properties of the global object and used to be overwritable.

Properties of the Number constructor have always been read only:

Number.POSITIVE_INFINITY = 123;
Number.POSITIVE_INFINITY; // Infinity

Specs:

ECMAScript 1st Edition (June 1997)

15.1.1.2 Infinity

The initial value of Infinity is +∞.

15.7.3.6 Number.POSITIVE_INFINITY

The value of Number.POSITIVE_INFINITY is +∞.

This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.

ECMAScript 5th Edition (December 2009)

In ES5, the value properties of the global object were made read only:

15.1.1.2 Infinity

The value of Infinity is +∞ (see 8.5).

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

The properties of the Number constructor didn’t really change, but the attributes were renamed:

15.7.3.6 Number.POSITIVE_INFINITY

The value of Number.POSITIVE_INFINITY is +∞.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

As of ES2018 these definitions have not changed.


About isFinite:

I once posted a question as to why the Google Closure Library implements a custom function for isFinite, and the answer was that there was probably some cross-browser inconsistency, although it’s unclear which browser and which inconsistency.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)