CKTIS / JavaScript
Exponentiation operator **
The ** operator raises a base to a given power. Learn its right associativity, the syntax rules for negative bases, and the differences between Number and BigInt calculations.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
base ** exponentThe ** operator raises its left operand (the base) to the power specified by its right operand (the exponent): 2 ** 3 produces 8. It performs exponentiation, unlike ^, which performs bitwise exclusive OR. Operands are converted to numeric values; after conversion, both must be Number or both BigInt. Mixing these types throws a TypeError.
The operator is right-associative: 2 ** 3 ** 2 means 2 ** (3 ** 2) and produces 512, not 64. It has higher precedence than *, /, and %. Associativity determines grouping, not a change in operand evaluation order.
An expression with unary minus, such as -2, requires parentheses when used as the base: -2 ** 2 causes a SyntaxError. Writing (-2) ** 2 produces 4, whereas -(2 ** 2) produces -4. Prefix increment (++) and decrement (--) expressions can be used as the base without parentheses: ++x ** 2 is valid syntax. A negative exponent is allowed without parentheses: 2 ** -2 produces 0.25.
For Number, the exponent may be fractional, but a finite negative base with a finite noninteger exponent produces NaN. For example, (-Infinity) ** 0.5 produces Infinity, not NaN, because the base is not finite. Results may involve floating-point rounding. For BigInt, the exponent must be nonnegative, or a RangeError is thrown. 0 ** 0 produces 1, and 0n ** 0n produces 1n.
Examples
console.log(2 ** 3);
console.log(2 ** 3 ** 2);
console.log((-2) ** 2, -(2 ** 2));
console.log(2 ** -2);
console.log(String(2n ** 10n));Result
8 512 4 -4 0.25 1024
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.