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.
const power = 3;
const number = 4;
console.log("power-operator:", number ** power);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.
let num = 5;
num **= 2;
console.log("power-assign:", num);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.
const power = 3;
const number = 4;
console.log("math-pow:", Math.pow(number, power));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.
