Javascript Number Type Range of Values

Introduction

The smallest number that can be represented in Javascript is stored in Number.MIN_VALUE.

Number.MIN_VALUE is 5e-324 on most browsers.

The largest number is stored in Number.MAX_VALUE and is 1.7976931348623157e+308 on most browsers.

If a calculation results in a number that cannot be represented by JavaScript's numeric range, the number automatically gets the special value of Infinity.

Any negative number that can't be represented is -Infinity (negative infinity).

Any positive number that can't be represented is simply Infinity (positive infinity).

Both positive or negative Infinity cannot be used in any further calculations.

To determine if a value is finite, use isFinite() function.

This function returns true only if the argument is between the minimum and the maximum values:

let result = Number.MAX_VALUE + Number.MAX_VALUE; 
console.log(isFinite(result));  // false 

We can get the values of positive and negative Infinity by accessing Number.NEGATIVE _INFINITY and Number.POSITIVE _INFINITY.




PreviousNext

Related