calculate pi plus infinity in javascript

In JavaScript, if we add a finite number to infinity, the answer will be infinity. Therefore, if we try to add Math.PI to Infinity, the answer will be infinity.

Here's the code:

index.tsx
const result = Math.PI + Infinity;
console.log(result); // Output will be "Infinity"
85 chars
3 lines

If you want to check if a number is equal to infinity or not, you can use the isFinite() function. Here's an example:

index.tsx
const result = Math.PI + Infinity;
console.log(isFinite(result)); // Output will be "false"
92 chars
3 lines

In this case, the isFinite() function will return false because the result is infinity, which is not a finite number.

gistlibby LogSnag