Sometimes, we want to do exponentiation in JavaScript.
In this article, we’ll look at how to do exponentiation in JavaScript.
How to do exponentiation in JavaScript?
To do exponentiation in JavaScript, we can use the Math.pow
method or the **
operator.
For instance, we write
const a = Math.pow(12, 2);
or
const a = 12 ** 2;
to call Math.pow
to raise 12 to the power of 2.
We can also do the same thing with the **
operator.
Therefore, a
is 144.
Conclusion
To do exponentiation in JavaScript, we can use the Math.pow
method or the **
operator.