JavaScript 数字文字混淆中的指数

JavaScript exponent in Number literal confusion

也许是时候再喝杯咖啡了,但我看到了一个我没想到会看到的奇怪问题。

我正在阅读 JavaScript 好的部分,在语法部分我看到以下内容:

If a number literal has an exponent part, then the value of the literal is computed by multiplying the part before the e by 10 raised to the power of the part after the e. So 100 and 1e2 are the same number.

From pg. 8 of JavaScript: The Good Parts by Douglas Crockford. Copyright 2008 Yahoo! Inc., 978-0-596-51774-8.

我是不是认为 2e2 应该等于 400?

按照书上的说法,这个值不应该是(2*10)^2吗?

在我的控制台中显示 2e2 == 200.. 我的数学、阅读理解或其他方面有问题吗?我需要 return 基础代数吗?

提前致谢。

2e2 被解释为 2*(10^2) 而不是 (2*10)^2。前者的计算结果为 2 * 100,等于 200。后者的计算结果为 20 ^ 2,这就是您得到 400 的原因。

这里e前面的部分是2。 e 之后的部分是 2。 e = Math.pow(10,2) 后的部分的10次方为100 所以将e之前的部分乘以10的e之后的部分的次方是2*Math.pow(10,2) = 200.