### 8e3评估的是多少？

#### [英]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.

## 4 个解决方案

### #1

35

`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^".

8e3是三次幂的八倍，即8000.这被称为科学（或指数）符号。试想一下，“e”代表“* 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.

### #2

17

This is called floating point notation or scientific notation. It is 8×10³, which is 8000 miliseconds. The e stands for 10th exponent. Let me give you some more examples:

``````1e3    = 1000        // 1×10³
1e0    = 1           // 1×10⁰
1e-1   = 0.1         // 1×10⁻¹ -> Works also for the negatives
1.23e9 = 1230000000  // And really makes sense to shorten big numbers
``````

There is also an wikipedia article on that topic: Scientific Notation

### #3

9

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

8e3正好是8000，所以时间恰好是8秒。

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

### #4

9

8*103 = 8000 ms which is 8 seconds

8 * 103 = 8000 ms，即8秒