To exponentiate numbers with JavaScript, we can use the **
operator or the Math.pow
method.
For instance, we can write:
const num = 2 ** 3
or:
const num2 = Math.pow(2, 3)
The first operand if **
is the base and the 2nd is the exponent.
The first argument of Math.pow
is the base and the 2nd is the exponent.
As a result, we get 8 for num
and num2
.