What number does 8e3 evaluate to?

前端 未结 4 1955
有刺的猬
有刺的猬 2020-12-20 11:15

I encountered this code today:

b = setTimeout(function () {
    // do some javascript stuff here
}, 8e3)

The timeout is set to 8e3

4条回答
  •  天涯浪人
    2020-12-20 12:02

    8e3 is exactly 8000, so the time is exactly 8 seconds.

    This could be chosen (eg. by some code minifiers) because it takes exactly 3 characters instead of 4 to represent 8000. Which means you gain 25% in terms of space in this single place :)

    And this is not "strange" notation, it is just another way of expressing numbers: Floating point notation

提交回复
热议问题