Fixed assignment operators a bit

This commit is contained in:
Teascade 2017-08-27 00:24:05 +00:00
parent 649ff070d8
commit 17c9b4f2bc
1 changed files with 11 additions and 10 deletions

View File

@ -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.
There are also two kinds of "special" assignment operators:
- `++` increment unary operator functions like `+= 1`
- `--` decrement unary operator functions like `-= 1`
All assignment operators return the value the assignee (leftside of the operator) was after the operator. For more examples:
```
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:
```
@ -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.
```
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 are areas of code surrounded by brackets `{}`. E.g.