Exponentiation (**)
Raises the left operand to the power of the right operand.
Syntax
base ** exponent
Returns
number — `base` raised to the power `exponent` (or a BigInt if both operands
are BigInts).
Examples
console.log(2 ** 10);
console.log(9 ** 0.5);
Output
1024
3
console.log(2 ** -1);
Output
0.5
let n = 3;
n **= 4;
console.log(n);
Output
81
Notes
- Right-associative: `2 ** 3 ** 2` is `2 ** (3 ** 2)` = 512.
- A unary minus on the base must be parenthesized: `(-2) ** 2`.
- Equivalent to `Math.pow()` but also supports BigInt.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 52 |
| firefox | 52 |
| safari | 10.1 |
| edge | 14 |
| node | 7.0 |