Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Exponentiation operator

The exponentiation operator ** raises a base to an exponent, including fractional exponents. It is right-associative, so chained expressions group from the right.

How it works

The ** operator raises a base value to an exponent. JavaScript evaluates chained exponentiation from right to left, so a ** b ** c means a ** (b ** c); fractional exponents can express roots.

Syntax

a ** b

Parameters

NameTypeDescription
anumber or BigIntThe base value to raise to a power; it is coerced to a numeric value.
bnumber or BigIntThe exponent applied to the base; it is coerced to a numeric value.

Returns

The result of raising the first operand to the power of the second operand.

Key points

  • The left operand is the base and the right operand is the exponent.
  • Exponents do not have to be integers; fractional values can represent roots, such as a square root with an exponent of one-half.
  • The operator has separate numeric and BigInt behavior depending on the operand types.
  • Before calculating, JavaScript converts both operands to numeric values and determines which numeric mode applies.
  • Zero has defined results for nonnegative exponents: a positive exponent gives zero, while exponent zero gives one.
  • A chain of exponentiation groups from the right, so the rightmost exponentiation is formed first.

Common mistakes

  • Chained exponentiation is right-associative, unlike most arithmetic operators: 2 ** 3 ** 2 is 2 ** (3 ** 2), producing 512.
  • A BigInt base and a Number exponent cannot be combined; use BigInt operands consistently when using BigInt exponentiation.

Example: Basic exponentiation and associativity

const squareRoot = 4 ** (1 / 2);
const nested = 2 ** 3 ** 2;

console.log(squareRoot); // 2
console.log(nested);     // 512

The operator raises its left operand to the power of its right operand; chaining groups from right to left.

When to use it

Powers

Compute powers directly in numeric expressions.

Roots

Express roots using fractional exponents, such as value ** (1 / 2).

Nested exponentiation

Use right-associative chaining when one exponent depends on another.

Interview questions

QWhat does the exponentiation operator do?

** raises the first operand to the power of the second, so 3 ** 4 evaluates to 81. It also supports fractional exponents, such as 4 ** (1 / 2), which evaluates to 2.

Follow-up: How does 2 ** 3 ** 2 group? It is 2 ** (3 ** 2) because exponentiation is right-associative, so the result is 512.

QHow is chained exponentiation evaluated?

Exponentiation is right-associative. Therefore, a ** b ** c is parsed as a ** (b ** c), rather than (a ** b) ** c.

Follow-up: How can left grouping be requested? Use parentheses, as in (2 ** 3) ** 2, which evaluates to 64 instead of 512.

QCan ** operate on BigInts?

The operator supports both Number and BigInt exponentiation, but both operands must resolve to the same numeric type. Mixing a BigInt with a Number throws a TypeError.

Follow-up: What happens when numeric strings are used? Operands are coerced to numeric values before JavaScript selects Number or BigInt exponentiation; incompatible resulting types still fail.

  • Math.pow()
  • Exponentiation assignment (**=)
  • Operator precedence

Source: Basic operators, maths. Checked 2026-10-15.