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>*/
Try in Playground

For a more natural reading, you can alternatively write:

/*<operand>*/ to power of /*<operand>*/
Try in Playground

Here is a practical example:

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
Try in Playground

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
Try in Playground