Javascript Learn Infinity Property Basics

Infinity Property

Infinity is a property of a Global Object, that specifies positive values of a numeric data. The default value of infinity is Number.POSITIVE_INFINITY.

 It represents Mathematical Infinity value. In mathematical calculations, Any value is divided by Zero is returned infinity



Example Usage

The number value is divided by Zero. and Infinity value is always the largest value of any numeric value When you are adding/multiply any value with infinity will get Infinity

console.log(123/0) // Infinity  
console.log(Infinity) // Infinity  
console.log(Infinity - Infinity) // NaN  
console.log(Infinity+Infinity) // Infinity  
console.log(Infinity*Infinity) // Infinity  

Infinity value is represented in Positive and Negative Number.POSITIVE_INFINITY - Represents Positive infinite values - Infinity Number.NEGATIVE_INFINITY - Represents Negative Infinite value - -Infinity Infinity property usages

  1. This will be used to check arithmetic operations result in comparison with Infinity.
  2. This will also be used to store the infinite value of any calculations
  3. Checking infinite value for Division

Check and Compare Infinity value 

Infinity can be used like a variable in conditional if the expression

var value = 45;  
if (45

output is

Value is less than infinite value

Number isFinite() method

isFinite() is defined in Number Object. isFinite() method checks value for a finite number, return true for a finite number, false for infinite number Syntax


Example Following is an example of isFinite() method of usage.

console.log(Number.isFinite(123)) // true  
console.log(Number.isFinite(Infinity)) //false  
console.log(Number.isFinite(null)) //false  
console.log(Number.isFinite(NaN)) //false  
console.log(Number.isFinite(-Infinity)) //false  
console.log(Number.isFinite(undefined)) //false  

Similar Posts