• JavaScript Video Tutorials

JavaScript Number POSITIVE_INFINITY Property



The JavaScript Number POSITIVE_INFINITY is a static data property that represents the positive infinity value. The positive infinity value in JavaScript is the same as the positive value of the global "Infinity" property.

Note: If you try to access it using x.POSITIVE_INFINITY, where 'x', is a variable, it will return undefined.

Syntax

Following is the syntax of JavaScript Number POSITIVE_INFINITY property −

Number.POSITIVE_INFINITY

Parameters

  • It does not accept any parameters.

Return value

This property has no return value.

Example 1

The following program demonstrates the usage of the JavaScript Number POSITIVE_INFINITY property. It will return 'Infinity' for Number.POSITIVE_INFINITY.

<html>
<head>
<title>JavaScript Number POSITIVE_INFINITY Property</title>
</head>
<body>
<script>
   document.write("positive infinity = ", Number.POSITIVE_INFINITY);
</script>
</body>
</html>

Output

The above program returns the positive infinity in JavaScript as 'infinity'.

positive infinity = Infinity

Example 2

If you try to access this property using any variable, it returns undefined.

The following is another example of the JavaScript Number POSITIVE_INFINITY property. Here, we are trying to find the positive infinity by using x.POSITIVE_INFINITY, where "x" is a variable with the value 2.

<html>
<head>
<title>JavaScript Number POSITIVE_INFINITY Property</title>
</head>
<body>
<script>
   let x = 2;
   document.write("x = ", x);
   document.write("<br>positive infinity = ", x.POSITIVE_INFINITY);
</script>
</body>
</html>

Output

This will return 'undefined' for x.POSITIVE_INFINITY.

x = 2
positive infinity = undefined

Example 3

If you multiply the Number.POSITIVE_INFINITY property with zero, the result will be NaN (Not a Number).

<html>
<head>
<title>JavaScript Number POSITIVE_INFINITY Property</title>
</head>
<body>
<script>
   document.write("Result of 'Number.POSITIVE_INFINITY * 0' = ", Number.POSITIVE_INFINITY * 0);
</script>
</body>
</html>

Output

The above program returns 'NaN' in the output −

Result of 'Number.POSITIVE_INFINITY * 0' = NaN

Example 4

In this example, we use the Number.POSITIVE_INFINITY property to check if a number is equal to positive infinity. If it is, we return a statement; otherwise, we return the number itself.

<html>
<head>
<title>JavaScript Number POSITIVE_INFINITY Property</title>
</head>
<body>
<script>
   function check(num){
      if(num == Number.POSITIVE_INFINITY){
         return "Number is equal to positive infinity...!";
      }
      else{
         return num;
      }
   }
   //call the function
   document.write("Result of check(-Number.MAX_VALUE) is: ", check(-Number.MAX_VALUE));
   document.write("<br>Result of check(-Number.MAX_VALUE * 2) is: ", check(-Number.MAX_VALUE*2));
</script>
</body>
</html>

Output

The above program returns output based on the satisfied condition −

Result of check(-Number.MAX_VALUE) is: -1.7976931348623157e+308
Result of check(-Number.MAX_VALUE * 2) is: Number is equal to positive infinity...!
Advertisements