If you try 9n**9n**9n in Chrome's console, Chrome breaks (it resembles an infinite loop). Why does this happen?

前端 未结 3 1347
半阙折子戏
半阙折子戏 2021-02-14 04:16

If you try 9n**9n**9n in Chrome\'s console, Chrome breaks (it resembles an infinite loop).

  • Does the V8 engine lack the implementation for this case?
3条回答
  •  粉色の甜心
    2021-02-14 04:40

    Background information:

    In JavaScript you can use n suffix for making the number as bigint (simpy big numbers). Big numbers have different ways of computations. Usually they are more "expensive" to compute. It does not use the processors built-in methods for calculations. Instead bigints use soft computations.

    Description of the issue:

    9n**9n means 9^9 (9*9*9*9*9*9*9*9*9). It is 387420489. Even if you multiply 387420489 by itself it is really big number. But **9n means you want to compute 387420489^9 which is really really very big number. It seems for chrome it takes too long to calculate it or some unknown issue happens.

    Basically it must be a bug which needs to be reported. Freezing the browser in weird way is not good user experience.

提交回复
热议问题