Skip to content

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!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.