JavaScript Code


JavaScript Infinity


Infinity in JavaScript

Infinity represents numeric value of infinity

Infinity is a global property that is read only, and always greater than any other number. similarly -Infinity is the smallest of all the numbers

Divided by Zero

if a positive integer is divided by zero, it mathematically results in an infinity value. in JavaScript, the same operation would return the value Infinity

var n = 3 / 0;
console.log(n);

Operations with Infinity

in the following examples, we will use Infinity in expressions, and observe the output

console.log(Infinity );
// Infinity
console.log(Infinity + 1);
// Infinity
console.log(Infinity - Infinity);
// NaN
console.log(Math.pow(10, 1000));
// Infinity
console.log(Math.log(0));
// -Infinity
console.log(1 / Infinity );
// 0
console.log(1 / 0);
// Infinity