Categories
JavaScript Answers

How to Exponentiate Numbers with JavaScript?

Spread the love

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 .

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 *