Difference between ECMAScript 2016 exponentiation operator and Math.pow()
None. As you can read in the ES7 spec, both Math.pow
and the **
exponentation operator cast their arguments/operands to numbers and use the very same algorithm to determine the result.
Addendum: this changed with the introduction of the BigInt type in ES2020, whose values are only supported by operators (including **
) but not the Math
object.
Late to the party -- I just wanted to add that as much as there is no difference between the two ways, I recently came to realize that the **
exponentiation operator isn't supported in Internet Explorer, so developers that are interested in extensive cross-browser support for their applications, may prefer to choose the Math.pow(...)
over the exponentiation operator.