Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I encountered this code today:

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

The timeout is set to 8e3. What time does this equate to in milliseconds, and why would anyone choose this strange notation? The code appears to be fully functional.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
474 views
Welcome To Ask or Share your Answers For Others

1 Answer

8e3 is eight times ten to the power of three, that is, 8000. This is called scientific (or exponential) notation. Just imagine the "e" stands for "*10^".

In this case there isn't much point in using that notation, but once you start getting to larger numbers, exponential notation becomes more readable. To figure out how much "1000000000" is you'd have to count zeros, but 1e9 is immediately obvious.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...