Exponentiation operation
Learn how to raise a number to a power.
The exponentiation operation raises a number to a power and returns the result.
To use the exponentiation operator, place a ** sign between two numeric values:
/*<operand>*/ ** /*<operand>*/
For a more natural reading, you can alternatively write:
/*<operand>*/ to power of /*<operand>*/
Here is a practical example:
2 ** 3 // 8
Note that exponentiation has higher precedence than multiplication, division, addition, and subtraction. This means that exponentiation is performed before those operations, as shown below:
2 + 3 ** 2 // 11, not 25
Also, note that exponentiation has different associativity than the other arithmetic operations. This means that exponentiation is performed from right to left, as shown below:
2 ** 3 ** 2 // 512, not 64