**) Der Potenzierungsoperator (**) ist ein Feature von ECMAScript 2016 von Rick Waldron.
> 6 ** 2
36
** ist ein Infixoperator für Potenzierung
x ** y
liefert das gleiche Ergebnis wie
Math.pow(x, y)
Normale Verwendung
const squared = 3 ** 2; // 9
Potenzierungszuweisungsoperator
let num = 3;
num **= 2;
console.log(num); // 9
Verwendung von Potenzierung in einer Funktion (Satz des Pythagoras)
function dist(x, y) {
return Math.sqrt(x**2 + y**2);
}
Der Potenzierungsoperator bindet sehr stark, stärker als * (was wiederum stärker bindet als +)
> 2**2 * 2
8
> 2 ** (2*2)
16