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

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

javascript - What number does 8e3 evaluate to?

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...