Get Infinite number in JavaScript & ReactJs – Code Example

To get an infinite number in Javascript and ReactJs, you can use Infinity property of global scope. No number is greater than this. You can use it to compare a very large number. Check the code example –

const maxNumber = Math.pow(10, 1000); // max positive number

if (maxNumber === Infinity) {
  console.log('Let\'s call it Infinity!');
  // expected output: "Let's call it Infinity!"
}

console.log(1 / maxNumber);
// expected output: 0

Source: MSDN

In reactjs use it like this –

window.Infinity