-2

In JavaScript maximum value, a number can have is get from Number.MAX_VALUE property. If I console,

console.log(isFinite(Number.MAX_VALUE)); // true

Getting true is expected. But I am expecting false in below statement as I am adding 1 to maximum value.

console.log(isFinite(Number.MAX_VALUE + 1));

But it is returning true. What is the reason?

Adding one more case. Following line output false as expected.

console.log(isFinite(Number.MAX_VALUE * Number.MAX_VALUE));

Question mentioned in this stackoverflow question explains maximum integer value. But I need to know how a number exceeding maximum float value works.

Community
  • 1
  • 1
Joby Joseph
  • 2,177
  • 3
  • 15
  • 19

1 Answers1

0

Number.MAX_VALUE + 1 is not Infinity.

You should read this question, and this answer for a good explanation.

As for isFinite, very simply:

If the argument is NaN, positive infinity, or negative infinity, this method returns false; otherwise, it returns true.

From the MDN. See also: Number.isFinite.

Community
  • 1
  • 1
Oka
  • 23,367
  • 6
  • 42
  • 53