Matt Matt - 24 days ago 12
Javascript Question

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

What is the benefit to using the ECMAScript 2016 exponentiation operator over the current

Math.pow()
? In other words, besides reducing key strokes, what is the difference between

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

Answer

None. As you can read in the spec draft, both Math.pow and the ** exponentation operator cast their arguments/operands to numbers and use the very same algorithm to determine the result.

Comments