+ 5

What is the order for multiple assignment operators on one line?

Sorry if the question was already asked, I didn't find an answer... I was wondering what how variables are exactly assigned when there are multiple assignement operators on one line. For example: var x=0; var y=6; x += y /= 3; So is it assigned like x = x+y and then y = y/3? That means x=6 and y=2. or is it first y = y/3 (also 2) and then x=x+y where x=2 (not 6). I hope my question is clear... I post it for Javascript, but I guess the rule will be the same for other languages like Java (?) Thank you very much for your help!!! Sololearn rocks! 🤘

8th Mar 2019, 1:03 PM
Adrien Zettl
Adrien Zettl - avatar
3 Respostas
+ 4
Nope, both x and y equals 2 (tested) I think js performed right side thing before assigning x. y /= 3 // 6/3 = 2 x += y // 0+2 = 2 Hope you got it
8th Mar 2019, 1:15 PM
Seniru
Seniru - avatar
+ 4
Thanks! Got it! 👍
8th Mar 2019, 10:06 PM
Adrien Zettl
Adrien Zettl - avatar
8th Mar 2019, 1:20 PM
Mike
Mike - avatar