Skip to content

Commit f7af08a

Browse files
committed
Add advanced operators for numbers
1 parent 2204b07 commit f7af08a

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
* [Numbers](numbers/README.md)
88
* [Creation](numbers/create.md)
99
* [Basic Operators](numbers/operators.md)
10+
* [Advanced Operators](numbers/advanced.md)
1011

numbers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ JavaScript has only one type of numbers, it does not define different types of n
44

55
There is nothing magical or strange going on with these. You define variables and set their values to any number type.
66

7-
In this chapter, we'll learn how to create number and do some operations on them (like additions, subtractions, ...).
7+
In this chapter, we'll learn how to create number and do some operations on them (like additions and subtractions).

numbers/advanced.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1+
# Advanced Operators
12

3+
Some advanced operators can be used, such as:
4+
5+
* **Modulus (division remainder)**: ```x = y % 2```
26
* **Increment**: Given a = 5
37
* ```c = a++```, Results: c = 5 and a = 6
48
* ```c = ++a```, Results: c = 6 and a = 6
59
* **Decrement**: Given a = 5
610
* ```c = a--```, Results: c = 5 and a = 4
7-
* ```c = --a```, Results: c = 4 and a = 4
11+
* ```c = --a```, Results: c = 4 and a = 4
12+
13+
14+
15+
---
16+
17+
Define a variable `c` as the modulus of the decremented value of `x` by 3.
18+
19+
```js
20+
var x = 10;
21+
22+
var c =
23+
```
24+
25+
```js
26+
var x = 10;
27+
28+
var c = (x--) % 3;
29+
```
30+
31+
```js
32+
assert(c == 1);
33+
```
34+
35+
---

0 commit comments

Comments
 (0)