From 17c9b4f2bc2f6c157e488ab09a439b5b85f7e028 Mon Sep 17 00:00:00 2001 From: Teascade Date: Sun, 27 Aug 2017 00:24:05 +0000 Subject: [PATCH] Fixed assignment operators a bit --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2856090..38fa63b 100644 --- a/README.md +++ b/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. -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.