What number does 8e3 evaluate to?

前端 未结 4 1956
有刺的猬
有刺的猬 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 11:47

    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

提交回复
热议问题