Infinity Property in JavaScript

JavaScript | Infinity Property: Here, we are going to learn about the Infinity Property in JavaScript with its syntax and examples.
Submitted by Siddhant Verma, on January 10, 2020

JavaScript | Infinity Property

The infinity property in JavaScript is much like the concept of infinity in mathematics where it is used to represent a number that is beyond our knowledge or one which cannot be expressed.

console.log(Infinity);
console.log(-Infinity);

Output

Infinity
-Infinity

Logging both positive infinity and negative infinity on the console does not give us the values of the numbers which indicates that in JavaScript too, infinity holds a perception of a very large number.

You can easily deduce what large numbers are in a programming language. They are numbers that go out of range.

console.log(3.4576917263943217389012348562315E+1203466)

Output

Infinity

This means that the number 3.4576917263943217389012348562315E+1203466 is considered an extremely large number and it indeed is since it falls out of the range of floating-point representation. As we know that JavaScript uses the floating-point representation to store numbers such large numbers are interpreted as Infinity.

console.log(-3.4576917263943217389012348562315E+1203)

Output

-Infinity

A number out of range of floating-point representation on the positive number line is interpreted as positive infinity and the number out of range of floating-point representation on the negative number line is interpreted as negative infinity.

console.log(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999);

Output

1e+219

The above number seems extremely large, doesn't it? However, if you look at 1e+219 and compare it with the infinity number 3.4576917263943217389012348562315E+1203 it seems extremely small! You can imagine how huge the limit of the floating-point representation is by comparing a huge number that you can imagine or think to the actual limit which is even beyond your imagination!

JavaScript Built-in Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.