+ 5

[Explanation] How assignment operators work.

For example: We want to calculate (x) and (y) using the (+=) operator. var (y) is assigned to let's say 10 (var y = 10;) var (x) will be whatever the user inputs. Let's say my input is 4. So, I want to find out the value of (x += y) In more detail: var y = 10; var x = //user input, or in this case 4. var x = x + y; var x = //changes from 4 to 14. //The output of var (x) would be 14. The same calculation can be performed like this. var y = 10; var x = //user input, or in this case 4. var n = x + y; //The output of var (n) would be 14. Note: We used 3 variables (x), (y) and (n). Whereas using the (+=) operator, we only used 2, (x) and (y), but (x) acts as two variables. Value is temporarily stored to var (x) in this case it's 4. Addition (+) var x = 4 + 10; or var x += y; The result (14) is reassigned (=) to var (x). https://jsfiddle.net/7e1x71Lo/6/ This works the same for any other assignment operator. Also, my explanation might be wrong. So, feel free to correct me.

8th Dec 2016, 3:00 PM
Lukas 16
Lukas 16 - avatar
3 Respostas
+ 4
Thumbs up, nice explanation ;)
9th Dec 2016, 3:47 PM
ein siedler
ein siedler - avatar
+ 2
x and y are just some values
27th Jan 2017, 7:43 PM
Andrei Iliescu
Andrei Iliescu - avatar
0
what is x and y? sorry if it is a stupid question. I know that it is horizontally and vertically, but what does that have to do with this?
13th Dec 2016, 12:16 PM
Mattis Kristensen
Mattis Kristensen - avatar