Open In App

What is negative infinity in JavaScript ?

Improve
Improve
Like Article
Like
Save
Share
Report

The negative infinity in JavaScript is a constant value that is used to represent a value that is the lowest available. This means that no other number is lesser than this value. It can be generated using a self-made function or by an arithmetic operation. 

Note: JavaScript shows the NEGATIVE_INFINITY value as -Infinity.

Negative infinity is different from mathematical infinity in the following ways:

  • Negative infinity results in -0(different from 0 ) when divided by any other number.
  • When divided by itself or positive infinity, negative infinity return NaN
  • Negative infinity, when divided by any positive number (apart from positive infinity) is negative infinity.
  • Negative infinity, divided by any negative number (apart from negative infinity) is positive infinity.
  • If we multiply negative infinity with NaN, we will get NaN as a result.
  • The product of 0 and negative infinity is Nan.
  • The product of two negative infinities is always a positive infinity.
  • The product of both positive and negative infinity is always negative infinity.

Syntax: 

Number.NEGATIVE_INFINITY

Example 1: 

html




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
 
<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h3>
        What is negative infinity in JavaScript?
    </h3>
    <button onclick="geekPositiveInfinity()">
        Generate negative infinity
    </button>
    <p id="geek"></p>
    <script>
        function geekPositiveInfinity() {
            let n = (-Number.MAX_VALUE) * 2;
            document.getElementById("geek").innerHTML =
                "Here the number generated is twice of negative of Number.MAX_VALUE" + "<br>" +
                " which is lesser than lower limit" + "<br><br>" + n;
        }
    </script>
</body>
</html>


Output:  

JavaScript Negative Infinity

Example 2: 

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h3>
        Negative infinity in JavaScript
    </h3>
    <h4>
        Operations with Negative infinity
    </h4>
    <ol>
        <li id="divide">
            <b>Divide any number by NEGATIVE_INFINITY </b>
            <br>
            561 / Number.NEGATIVE_INFINITY =
        </li>
        <br>
        <li id="divideSelf">
            <b>Divide negative infinity by itself</b>
            <br>
            Number.NEGATIVE_INFINITY / Number.NEGATIVE_INFINITY =
        </li>
        <br>
        <li id="dividePos">
            <b>Negative infinity divided by any Positive number
                  (except Positive infinity)
              </b>
            <br>
            Number.NEGATIVE_INFINITY / 123 =
        </li>
        <br>
        <li id="divideNeg">
            <b>Negative infinity divided by any Negative number
                  (except Negative infinity)
              </b>
            <br>
            Number.NEGATIVE_INFINITY / -123 =
        </li>
        <br>
        <li id="mulnan">
            <b>Multiply Negative Infinity by NaN</b>
            <br>
            Number.NEGATIVE_INFINITY * NaN =
        </li>
        <br>
        <li id="mulZero">
            <b>Product of Zero and Negative infinity</b>
            <br>
            0 * Number.NEGATIVE_INFINITY =
        </li>
        <br>
        <li id="mulSelf">
            <b>Product of two Negative infinity</b>
            <br>
            Number.NEGATIVE_INFINITY * Number.NEGATIVE_INFINITY =
        </li>
        <br>
        <li id="mulInf">
            <b>Product of Negative infinity and Positive infinity</b>
            <br>
            Number.NEGATIVE_INFINITY * Number.POSITIVE_INFINITY =
        </li>
        <br>
    </ol>
    <button onclick="calc()">Click Here to calculate</button>
    <script>
        function calc() {
            document.getElementById("divide").innerHTML +=
                  561 / Number.NEGATIVE_INFINITY;
            document.getElementById("divideSelf").innerHTML +=
                  Number.NEGATIVE_INFINITY / Number.NEGATIVE_INFINITY;
            document.getElementById("dividePos").innerHTML +=
                  Number.NEGATIVE_INFINITY / 123;
            document.getElementById("divideNeg").innerHTML +=
                  Number.NEGATIVE_INFINITY / -123;
            document.getElementById("mulnan").innerHTML +=
                  Number.NEGATIVE_INFINITY * NaN;
            document.getElementById("mulZero").innerHTML +=
                  0 * Number.NEGATIVE_INFINITY;
            document.getElementById("mulSelf").innerHTML +=
                  Number.NEGATIVE_INFINITY * Number.NEGATIVE_INFINITY;
            document.getElementById("mulInf").innerHTML +=
                  Number.NEGATIVE_INFINITY * Number.POSITIVE_INFINITY;
        }
    </script>
</body>
</html>


Output:

JavaScript Negative Infinity

Recommended Article: JavaScript Infinity Property



Last Updated : 24 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads