The exponentiation operator (**) is a mathematical operator that raises the left operand to the power of the right operand. Introduced in ES2016 (ES7), it is the standard way to perform exponentiation in modern JavaScript.
let squared = 5 ** 2; // 25
let cubed = 2 ** 3; // 8
let root = 16 ** 0.5; // 4 (square root)
Math.pow()
The ** operator is functionally identical to Math.pow():
let value1 = 3 ** 4; // 81
let value2 = Math.pow(3, 4); // 81
** operator is right-associative: evaluated from right to left.a ** b ** c is a ** (b ** c).
let result = 2 ** 3 ** 2; // 2 ** (3 ** 2) => 2 ** 9 = 512
Use parentheses with negative bases to avoid confusion:
let a = (-2) ** 3; // -8
let b = -2 ** 3; // - (2 ** 3) = -8
**=
JavaScript also supports the exponentiation assignment operator (**=):
let x = 10;
x **= 2; // x = x ** 2 = 100
map().
let arr = [1, 2, 3, 4];
let squares = arr.map(n => n ** 2); // [1, 4, 9, 16]
** for powers, roots, and exponents.** in math-heavy code, array transformations, and interactive calculators.