-1

Why 888888888888888888888 equals 888888888888888900000 in JavaScript

console.log(888888888888888888888 === 888888888888888900000)

in chrome console

Calvin Nunes
  • 6,376
  • 4
  • 20
  • 48
Jason Christ
  • 125
  • 7

1 Answers1

1

That is because integers can only be precisely represented in JavaScript up to 2^53 - 1

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

The problem is that, after 2^53 - 1, there is not enough bits to represent the number. So, when you set a higher number, you lose information and what you are actually storing in memory is not reliable. In your case, these 2 numbers, after converting to binary, are the same. That is why they are equal

Andre Pena
  • 56,650
  • 48
  • 196
  • 243