Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Exponentiation (**)

Raises a number to a power.

Available since: ES2016

Syntax

base ** exponent

Examples

Powers and roots:

console.log(2 ** 10);
console.log(9 ** 0.5);
console.log(2 ** -1);

Output:

1024
3
0.5

The compound assignment:

let n = 3;
n **= 2;
 
console.log(n);

Output:

9

Notes

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

  • Math.pow — Raises a number to a power.
  • Math.sqrt — Returns the square root of a number.

In the tutorial

  • Operators — JavaScript arithmetic operators, the remainder, operator precedence, compound assignment, ++ and --.

Thanks for reading!

Donate to the site — we work hard for you.