How TO - JavaScript Exponentiation (**)


Learn how to use JavaScript Exponentiation (**).


Exponentiation Operator

The exponentiation operator (**) raises the first operand to the power of the second operand:

Example

let x = 5;
let z = x ** 2; // result is 25
Try it Yourself »

x ** y produces the same result as Math.pow(x, y):

Example

let x = 5;
let z = Math.pow(x,2); // result is 25
Try it Yourself »

Exponentiation Assignment

The exponentiation assignment operator (**=) raises the value of a variable to the power of the right operand.

Example

let x = 5;
x **= 2; // result 25
Try it Yourself »

Read more about JavaScript Operators in our JavaScript Operator Tutorial.


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.