closes #2547
This commit is contained in:
parent
797c65867b
commit
532b64f3d4
1 changed files with 9 additions and 5 deletions
|
@ -56,17 +56,21 @@ alert( 8 % 3 ); // 2, a remainder of 8 divided by 3
|
|||
|
||||
### 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:
|
||||
|
||||
```js run
|
||||
alert( 2 ** 2 ); // 4 (2 multiplied by itself 2 times)
|
||||
alert( 2 ** 3 ); // 8 (2 * 2 * 2, 3 times)
|
||||
alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2, 4 times)
|
||||
alert( 2 ** 2 ); // 2² = 4
|
||||
alert( 2 ** 3 ); // 2³ = 8
|
||||
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
|
||||
alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue