Typescript Infinity

The Infinity is a global property i.e. it is a variable in a global scope. The Infinity can be either POSITIVE_INFINITY & NEGATIVE_INFINITY. We can check whether the number is finite by using the isFinite method.

Infinity

Infinity can result in many ways. For Example, dividing any non zero number by zero results in infinity. The Typeof Infinity is a number

Any operations that result in a large number.

Dividing, Multiplying, and Adding to infinity is still infinity.

But dividing a number by Infinity is zero.

The following operations using infinity results in NaN.

POSITIVE_INFINITY & NEGATIVE_INFINITY

Infinity can be either positive or negative.

POSITIVE_INFINITY & NEGATIVE_INFINITY are static properties of Number object. We can access it using the Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY.

Comparisons

Comparing Infinity with numbers works correctly

isFinite

You can use the Number.isFinite method to verify whether the number is finite.

If you pass a string to isFinite, it will result in false.

Summary

Here we learned about infinity in Typescript. The Infinity is very large value, which cannot be represented as 64bit floating point. It can be either POSITIVE_INFINITY & NEGATIVE_INFINITY. We can use isFinite method to check if the given number is infinite.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top