Matt Matt - 5 months ago 45
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

? In other words, besides reducing key strokes, what is the difference between

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


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.