Categories
JavaScript Answers

How to do exponentiation in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *