I understand that Number.POSITIVE_INFINITY has a value of Infinity, and Number.NEGATIVE_INFINITY has a value of -Infinity.
Is there a reason I would use Number.POSITIVE_INFINITY instead of Infinity, or Number.NEGATIVE_INFINITY instead of -Infinity?
On a related note, are there any cross-browser issues with isFinite?
TL;DR
Infinityused to be overwritable;Number.POSITIVE_INFINITYandNumber.NEGATIVE_INFINITYhave always been read only.Infinityis a property of the global object (windowis the global object for Javascript run in the browser), whereasNumber.POSITIVE_INFINITYis a property of theNumberconstructor.Prior to the 5th Edition of ECMAScript, value properties of the global object were able to be overwritten:
The same applies to
undefinedandNaN, which are also properties of the global object and used to be overwritable.Properties of the
Numberconstructor have always been read only:Specs:
ECMAScript 1st Edition (June 1997)
ECMAScript 5th Edition (December 2009)
In ES5, the value properties of the global object were made read only:
The properties of the
Numberconstructor didn’t really change, but the attributes were renamed: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.