Math.pow() and Power Operator in JavaScript

Tech reviewed: Deepak Prasad
Math.pow() and Power Operator in JavaScript

JavaScript power operations are used when you need exponents, growth calculations, or repeated multiplication. The common choices are Math.pow() and the ** operator.

Math.pow() works with numbers, while the exponentiation operator also works with BigInt. If you are comparing other numeric helpers too, Math.abs in JavaScript and the other Math methods fit the same family.

Tested on: Node.js v20.18.2. A short note after each runnable snippet describes what you should see in the console.


Method 1: Use the exponentiation operator

** is the modern exponentiation operator.

javascript
const power = 3;
const number = 4;

console.log("power-operator:", number ** power);
Output

You should see one line logging power-operator: 64.

Use this when you want the clearest exponent syntax in modern JavaScript.


Method 2: Use the exponentiation assignment operator

**= raises the current value to the given power.

javascript
let num = 5;
num **= 2;
console.log("power-assign:", num);
Output

You should see one line logging power-assign: 25.

This is useful when you want to update the same variable in place.


Method 3: Use Math.pow() for Number values

Math.pow() returns the base raised to the exponent and works with numeric values.

javascript
const power = 3;
const number = 4;

console.log("math-pow:", Math.pow(number, power));
Output

You should see one line logging math-pow: 64.

Use Math.pow() when you want the older method style or are following existing code that already uses the Math object.


Summary

For JavaScript power operations, use ** for modern exponentiation, **= for in-place updates, and Math.pow() when you want the classic Math object form. The operator is the more flexible choice because it also supports BigInt.


Official documentation

Olorunfemi Akinlua

Boasting over five years of experience in JavaScript, specializing in technical content writing and UX design. With a keen focus on programming languages, he crafts compelling content and designs user-friendly interfaces to enhance digital …

  • JavaScript
  • Web Design