The exponentiation operator (
**) returns the result of raising the first
operand to the power of the second operand. It is equivalent to
except it also accepts BigInts as operands.
x ** y
The exponentiation operator is
a ** b ** c is equal to
a ** (b ** c).
In most languages, such as PHP, Python, and others that have an exponentiation operator
**), the exponentiation operator is defined to have a higher precedence
than unary operators, such as unary
+ and unary
-, but there
are a few exceptions. For example, in Bash, the
** operator is defined to
have a lower precedence than unary operators.
is, you cannot put a unary operator (
immediately before the base number; doing so will cause a SyntaxError.
-(2 ** 2) — to make the intention unambiguous.
2 ** 3 // 8 3 ** 2 // 9 3 ** 2.5 // 15.588457268119896 10 ** -1 // 0.1 NaN ** 2 // NaN
2 ** 3 ** 2 // 512 2 ** (3 ** 2) // 512 (2 ** 3) ** 2 // 64
To invert the sign of the result of an exponentiation expression:
-(2 ** 2) // -4
To force the base of an exponentiation expression to be a negative number:
(-2) ** 2 // 4
|ECMAScript Language Specification |
BCD tables only load in the browser