Fixed assignment operators a bit
This commit is contained in:
parent
649ff070d8
commit
17c9b4f2bc
21
README.md
21
README.md
@ -140,9 +140,17 @@ For example:
|
|||||||
|
|
||||||
If you however try to use these kinds of assignment operators on variabes which have not been initialized with a value yet, an exception will occur.
|
If you however try to use these kinds of assignment operators on variabes which have not been initialized with a value yet, an exception will occur.
|
||||||
|
|
||||||
There are also two kinds of "special" assignment operators:
|
All assignment operators return the value the assignee (leftside of the operator) was after the operator. For more examples:
|
||||||
- `++` increment unary operator functions like `+= 1`
|
|
||||||
- `--` decrement unary operator functions like `-= 1`
|
```
|
||||||
|
let test = 0;
|
||||||
|
let new = (test = 2); // new becomes 2, test becomes 2
|
||||||
|
let another = (new += 5); /// another becomes 7, new becomes 7.
|
||||||
|
```
|
||||||
|
|
||||||
|
**But** there are also two kinds of "special" assignment operators, which return the _old_ value of the assignee, after the operator.
|
||||||
|
- `++` increment unary operator which adds 1 to the leftside value.
|
||||||
|
- `--` decrement unary operator which subtracts 1 from the leftside value.
|
||||||
|
|
||||||
for example:
|
for example:
|
||||||
```
|
```
|
||||||
@ -151,13 +159,6 @@ let first = i++; // first becomes 0, i increments to 1
|
|||||||
let second = i--; // second becomes 1, i decrements back to 0.
|
let second = i--; // second becomes 1, i decrements back to 0.
|
||||||
```
|
```
|
||||||
|
|
||||||
All assignment operators return the value the assignee (leftside of the operator) was before the operator. For more examples:
|
|
||||||
|
|
||||||
```
|
|
||||||
let test = 0;
|
|
||||||
let new = (test = 2); // new becomes 0, test becomes 2
|
|
||||||
let another = (new += 5); /// another becomes 0, new becomes 5.
|
|
||||||
```
|
|
||||||
|
|
||||||
## Scopes
|
## Scopes
|
||||||
Scopes are areas of code surrounded by brackets `{}`. E.g.
|
Scopes are areas of code surrounded by brackets `{}`. E.g.
|
||||||
|
Loading…
Reference in New Issue
Block a user