Math.pow()

ES1+

Returns the base to the exponent power.

Syntax

Math.pow(base, exponent)

Parameters

base number

The base number

exponent number

The exponent used to raise the base

Return Value

number

A number representing the given base taken to the power of the given exponent

Examples

JavaScript
console.log(Math.pow(2, 3));
console.log(Math.pow(4, 0.5));
console.log(2 ** 3); // 대안
Output:
// 8 2 8

📌 When to Use

Use Math.pow() for exponential calculations, compound interest, scientific formulas, or when you need more control than the ** operator.

⚠️ Common Mistakes

Not handling negative bases with fractional exponents, which return NaN (e.g., Math.pow(-8, 1/3)).

Confusing order of parameters - Math.pow(base, exponent), not Math.pow(exponent, base).

✅ Best Practices

In modern JavaScript, prefer the ** operator for cleaner code: 2 ** 3 instead of Math.pow(2, 3).

For nth roots, use Math.pow(x, 1/n) or x ** (1/n) for positive numbers only.

⚡ Performance Notes

Math.pow() and the ** operator have equivalent performance. For squaring numbers, x * x is faster than Math.pow(x, 2) or x ** 2.

🌍 Real World Example

Compound Interest Calculator

Calculate investment growth using the compound interest formula with annual compounding.

function calculateCompoundInterest(principal, rate, years, compoundsPerYear = 12) {
  // A = P(1 + r/n)^(nt)
  const amount = principal * Math.pow(
    (1 + rate / compoundsPerYear),
    compoundsPerYear * years
  );

  return {
    finalAmount: amount.toFixed(2),
    totalInterest: (amount - principal).toFixed(2),
    growthMultiplier: (amount / principal).toFixed(3)
  };
}

console.log(calculateCompoundInterest(10000, 0.07, 10));
// { finalAmount: '20096.61', totalInterest: '10096.61', growthMultiplier: '2.010' }

Related Methods