**
) The exponentiation operator (**
) is an ECMAScript 2016 feature by Rick Waldron.
> 6 ** 2
36
**
is an infix operator for exponentiation:
x
**
y
produces the same result as
Math
.
pow
(
x
,
y
)
Normal use:
const
squared
=
3
**
2
;
// 9
Exponentiation assignment operator:
let
num
=
3
;
num
**=
2
;
console
.
log
(
num
);
// 9
Using exponentiation in a function (Pythagorean theorem):
function
dist
(
x
,
y
)
{
return
Math
.
sqrt
(
x
**
2
+
y
**
2
);
}
The exponentiation operator binds very strongly, more strongly than *
(which, in turn, binds more strongly than +
):
> 2**2 * 2
8
> 2 ** (2*2)
16