References

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

The JavaScript Exponentiation ** operator

Operator JavaScript All modern browsers Updated
Quick answer

The exponentiation operator ** raises the left number to the power of the right. 2 ** 10 is 1024. It does the same thing as Math.pow() but reads more naturally in formulas. Use a fractional exponent for roots — 9 ** 0.5 is 3.

Overview

** is the exponentiation operator: base ** exponent raises the base to that power. 3 ** 2 is 9, 2 ** 10 is 1024. Added in ES2016, it's the concise, readable alternative to Math.pow(base, exponent) — identical in result, just nicer to read inside a larger expression.

It does everything Math.pow() does. A fractional exponent gives roots: 16 ** 0.5 is a square root (4), and 27 ** (1/3) is a cube root. A negative exponent gives a reciprocal: 2 ** -1 is 0.5.

Two syntax details. ** is right-associative, so 2 ** 3 ** 2 is 2 ** 9 (= 512), not 8 ** 2 — chains evaluate right to left. And you can't put a unary minus directly before the base without parentheses (-2 ** 2 is a syntax error); write (-2) ** 2 to make the intent clear. There's also a compound assignment form, x **= 2.

Syntax

base ** exponent

2 ** 10      // 1024
3 ** 2       // 9
16 ** 0.5    // 4 (square root)
2 ** -1      // 0.5 (reciprocal)
let x = 3; x **= 2;  // x is 9

Example

Live example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
  document.getElementById('out').textContent =
    '2 ** 10   = ' + (2 ** 10) + '\n' +
    '16 ** 0.5 = ' + (16 ** 0.5) + '\n' +
    '2 ** 3 ** 2 = ' + (2 ** 3 ** 2); // 1024 / 4 / 512 (right-assoc)
</script>

Best practices

  • Prefer ** over Math.pow() for inline math — it's cleaner to read.
  • Use a 0.5 exponent for square roots, or Math.sqrt() for clarity.
  • Wrap a negative base in parentheses: (-2) ** 2, since -2 ** 2 is a syntax error.
  • Remember it's right-associative — a ** b ** c evaluates as a ** (b ** c).

Frequently asked questions

What does the ** operator do?
It raises the left number to the power of the right, e.g. 2 ** 8 is 256. It's the same as Math.pow().
What is the difference between ** and Math.pow()?
None in result — ** is just a more concise operator form. 2 ** 3 equals Math.pow(2, 3).
How do I do a square root with **?
Use an exponent of 0.5: x ** 0.5. Or use Math.sqrt().
Why is -2 ** 2 a syntax error?
The language requires you to clarify the precedence of a unary minus with exponentiation. Write (-2) ** 2 or -(2 ** 2).