Exponential operator **

Operator syntax

Until the ES2016 standard, there was no exponential operator in JavaScript, but the method Math.pow was used. Now the “**” operator returns the result of scaling the base (first operand) with the exponent (second operand):

<strong>x<sup>y</sup></strong> = Math.pow(x, y) = <strong>x**y</strong>

Example

Example

In addition to this standard operator, we can use it with the operator “=”:

NOTE:
In JavaScript, it is not allowed to write so-called ambiguous code, so the following example returns an error:

It is therefore necessary to make it clear which operation has priority:

or