References

Beginner-friendly references for web development, with live, editable examples.

The JavaScript Math.pow() method

Method JavaScript All modern browsers Updated
Quick answer

The Math.pow() method raises a base to an exponent. Math.pow(2, 10) is 1024. Modern code often uses the exponentiation operator instead: 2 ** 10 does the same thing more concisely. Use a fractional exponent like 0.5 for roots — Math.pow(9, 0.5) is 3.

Overview

Math.pow(base, exponent) calculates the base raised to a power. Math.pow(2, 3) is 8 (two cubed), Math.pow(10, 6) is a million. It covers everything from squaring a value to compound-interest formulas.

Since ES2016 there's a tidier alternative: the exponentiation operator **. 2 ** 3 is exactly the same as Math.pow(2, 3), just shorter, and it reads naturally in formulas. Most modern code prefers **; Math.pow() remains perfectly valid and is handy when you want a function reference to pass around.

Fractional exponents give you roots: an exponent of 0.5 is a square root, so Math.pow(16, 0.5) is 4 (though Math.sqrt() is clearer for that). And 1/3 gives a cube root. Negative exponents give reciprocals — Math.pow(2, -1) is 0.5.

Syntax

Math.pow(base, exponent)

Math.pow(2, 10)    // 1024
2 ** 10            // 1024 (operator form)
Math.pow(9, 0.5)   // 3 (square root)
Math.pow(2, -1)    // 0.5

Parameters

The Math.pow() method accepts the following parameters.

Parameter Description
base The base number.
exponent The power to raise the base to. Fractions give roots; negatives give reciprocals.

Example

Live example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
  const principal = 1000, rate = 0.05, years = 3;

  const total = principal * Math.pow(1 + rate, years);

  document.getElementById('out').textContent =
    '2 ** 10 = ' + (2 ** 10) + '\n' +
    'compound: $' + total.toFixed(2); // 1024 / $1157.63
</script>

Best practices

  • Prefer the ** operator in modern code — 2 ** 3 is cleaner than Math.pow(2, 3).
  • Use a 0.5 exponent for square roots, though Math.sqrt() is clearer.
  • Keep Math.pow when you need a function reference to pass to higher-order functions.
  • Use negative exponents for reciprocals (x ** -1 is 1/x).

Frequently asked questions

How do I raise a number to a power in JavaScript?
Use Math.pow(base, exp) or the operator base ** exp. Both give the same result.
What is the difference between Math.pow() and **?
None in result — ** is the newer exponentiation operator and is just more concise. 2 ** 3 equals Math.pow(2, 3).
How do I calculate a square root with Math.pow()?
Use an exponent of 0.5: Math.pow(x, 0.5). Or use Math.sqrt(x), which is clearer.
What does a negative exponent do?
It gives the reciprocal: Math.pow(2, -2) is 0.25 (1 over 2 squared).