This commit is contained in:
Ilya Kantor 2021-03-26 08:13:54 +03:00
parent 797c65867b
commit 532b64f3d4

View file

@ -56,17 +56,21 @@ alert( 8 % 3 ); // 2, a remainder of 8 divided by 3
### Exponentiation ** ### Exponentiation **
The exponentiation operator `a ** b` multiplies `a` by itself `b` times. The exponentiation operator `a ** b` raises `a` to the power of `b`.
In school maths, we write that as a<sup>b</sup>.
For instance: For instance:
```js run ```js run
alert( 2 ** 2 ); // 4 (2 multiplied by itself 2 times) alert( 2 ** 2 ); // 2² = 4
alert( 2 ** 3 ); // 8 (2 * 2 * 2, 3 times) alert( 2 ** 3 ); // 2³ = 8
alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2, 4 times) alert( 2 ** 4 ); // 2⁴ = 16
``` ```
Mathematically, the exponentiation is defined for non-integer numbers as well. For example, a square root is an exponentiation by `1/2`: Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
For example, a square root is an exponentiation by ½:
```js run ```js run
alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root) alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root)