How to use JavaScript's power operator (**)

Learn how to use JavaScript to calculate power (**).

Power operator

Power operator (power operator,**Promote the first operand to the power of the second operand:

Example

let x = 5;
let z = x ** 2; // The result is 25

Try It Yourself

x ** y The result is Math.pow(x, y) Same:

Example

let x = 5;
let z = Math.pow(x, 2); // The result is 25

Try It Yourself

Power assignment

Power assignment operator (**=Promote the value of the variable to the power of the right operand.

Example

let x = 5;
x **= 2; // The result is 25

Try It Yourself

Related Pages

Tutorial:JavaScript Operators