Exponentiation (**)
Raises a number to a power.
Available since: ES2016
Syntax
base ** exponentExamples
Powers and roots:
console.log(2 ** 10);
console.log(9 ** 0.5);
console.log(2 ** -1);Output:
1024
3
0.5The compound assignment:
let n = 3;
n **= 2;
console.log(n);Output:
9Notes
The operator is right-associative: 2 ** 3 ** 2 is 2 ** 9, not 8 ** 2. A unary minus before the base needs parentheses: write (-2) ** 2.
See also
In the tutorial
- Operators — JavaScript arithmetic operators, the remainder, operator precedence, compound assignment, ++ and --.