Exponentiation in JavaScript

There is also a special operator for raising a number to a power **. Let's use it to raise the number 10 to the third power:

alert(10 ** 3); // shows 1000

Let's raise the value of the variable to a power:

let a = 10; alert(a ** 3); // shows 1000

It can occur that both the number and degree will be contained in variables:

let a = 10; let b = 3; alert(a ** b); // shows 1000

Raise the number 2 to the 10th power. Display the result on the screen.

Exponentiation precedence

The exponentiation operation takes precedence over multiplication and division. In the following example first the exponentiation and then multiplication will be performed:

alert(2 * 2 ** 3);

Without running the code, determine what will be displayed on the screen:

let a = 3 * 2 ** 3; alert(a);

Without running the code, determine what will be displayed on the screen:

let a = (3 * 2) ** 3; alert(a);

Without running the code, determine what will be displayed on the screen:

let a = 3 * 2 ** (3 + 1); alert(a);

Without running the code, determine what will be displayed on the screen:

let a = 2 ** 3 * 3; alert(a);

Without running the code, determine what will be displayed on the screen:

let a = 3 * 2 ** 3 * 3; alert(a);
enru