ECMAScript 2016 求幂运算符和 Math.pow() 之间的区别

Difference between ECMAScript 2016 exponentiation operator and Math.pow()

与当前 Math.pow() 相比,使用 ECMAScript 2016 exponentiation operator 有什么好处?也就是说,除了减少击键之外,

还有什么区别呢?

Math.pow(2, 2) => 42 ** 2 => 4

None。正如您在 ES7 规范中所读到的,两者都 Math.pow and the ** exponentation operator cast their arguments/operands to numbers and use the very same algorithm 来确定结果。

附录:随着ES2020中BigInt类型的引入而改变,它的值只被运算符支持(包括**)而不是[=13] =]对象。

Math.pow(2,2) === 2**2; // FALSE

Math.pow(99,99);
99 ** 99;

结果:

3.697296376497263e+197

3.697296376497268e+197

迟到了——我只是想补充一点,尽管这两种方式之间没有区别,但我最近才意识到 Internet Explorer 不支持 ** 求幂运算符,因此对应用程序的广泛 跨浏览器支持 感兴趣的开发人员可能更愿意选择 Math.pow(...) 而不是求幂运算符。