Cover Image for JavaScript Infinity PROPERTY
193 views

JavaScript Infinity PROPERTY

The JavaScript Infinity is a global property that represents positive infinity. It is a special numeric value that exceeds the upper limit of the number data type. It is often used to represent mathematical operations or calculations that result in an overflow or infinite value.

The Infinity property can be accessed and used like any other global property in JavaScript. Here are a few examples:

JavaScript
console.log(Infinity);        // Outputs: Infinity

console.log(10 / 0);          // Outputs: Infinity

console.log(Number.MAX_VALUE * 2);  // Outputs: Infinity

console.log(Infinity + 5);    // Outputs: Infinity

console.log(Infinity / Infinity);    // Outputs: NaN

console.log(typeof Infinity); // Outputs: 'number'

As shown in the examples, Infinity can be used in mathematical operations like division, addition, or multiplication to represent infinite or undefined results. It is also worth noting that certain operations involving Infinity, such as dividing Infinity by Infinity, result in NaN (Not a Number).

The typeof operator can be used to determine the data type of the Infinity property, which returns 'number' in this case.

It’s important to handle Infinity appropriately in your code to avoid unintended behavior or errors. It is often used in conditional checks or comparisons to handle scenarios where a value exceeds a certain limit or to handle special cases in mathematical calculations.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS