How to represent negative infinity in JavaScript?
Negative infinity in JavaScript is a constant value which is used to represent that no other number is lesser than this value.
Advertisements
Negative Infinity can be generated using a self-made function or using arithmetic operation.
var negInfinityNum = (-Number.MAX_VALUE) * 2; console.log(negInfinityNum); //-Infinity
You can check if this number is a negative infinity using Number.NEGATIVE_INFINITY.
if (negInfinityNum == Number.NEGATIVE_INFINITY) { console.log("Yes, it's negative infinity!"); } //Yes, it's negative infinity!