Skip to content

exponentiation (**)

In JavaScript, the exponentiation operator (**) raises its left operand, the base, to the power of its right operand, the exponent. It works on both numbers and bigints and returns a value of the same type as its operands.

For numbers, ** gives the same result as Math.pow(), but it also accepts bigint operands. It binds tighter than the other arithmetic operators and groups from the right, so 2 ** 3 ** 2 means 2 ** (3 ** 2). A unary operator such as - can’t sit directly before the base.

JavaScript Exponentiation Syntax

The operator sits between the base and the exponent:

Language: JavaScript Syntax
<base> ** <exponent>

Both operands are converted to numeric values first, and then they have to be both numbers or both bigints. Mixing the two types throws a TypeError.

JavaScript Exponentiation Examples

Say a client retries a failed request and doubles its wait before each new attempt. Raising 2 to the attempt number gives the delay in milliseconds:

Language: JavaScript
> const baseDelay = 100;
undefined

> baseDelay * 2 ** 3
800

> 2 ** 3 ** 2
512
> (2 ** 3) ** 2
64

Because ** binds tighter than *, the first expression computes 2 ** 3 before multiplying. The last two lines show the right-to-left grouping. Raising 2 ** 3 to a power takes parentheses.

Say a distance calculation squares an offset that may be negative. Writing -offset ** 2 is a SyntaxError, because the minus sign could apply before or after the power. Parentheses make the grouping explicit:

Language: JavaScript
> const offset = 2;
undefined

> (-offset) ** 2
4
> -(offset ** 2)
-4

Squaring (-offset) gives 4, while negating the square gives -4.

JavaScript Exponentiation Gotchas

  • A negative bigint exponent, as in 2n ** -1n, throws a RangeError instead of returning a fraction.
  • The expression NaN ** 0 returns 1, while 1 ** Infinity returns NaN.
  • A negative base with a fractional exponent returns NaN, so (-8) ** (1 / 3) doesn’t give the cube root -2.

JavaScript Exponentiation Use Cases

  • Squaring and cubing values in geometry and physics formulas
  • Computing exponential backoff delays and growth rates
  • Taking square roots and other roots with fractional exponents, such as x ** 0.5
  • Computing exact large powers of two with bigint operands, such as 2n ** 64n
A developer pulls a Math.floor() lever on a counting machine with a coffee sack on its scale, a big dial, a % gauge and a toFixed(2) receipt printer.

Course

JavaScript Numbers for Pythonistas

Port a coffee roastery's batch planner from Python to JavaScript, and learn to divide, round, read numbers from text, and format them with JavaScript's one number type.

basics js py

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 12, 2026