Categories
JavaScript Answers

How to Exponentiate Numbers with JavaScript?

Spread the love

Sometimes, we want to exponentiate numbers with JavaScript.

In this article, we’ll look at how to exponentiate numbers with JavaScript.

Exponentiate Numbers with JavaScript

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 .

Conclusion

To exponentiate numbers with JavaScript, we can use the ** operator or the Math.pow method.

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 *