+ 1

Please help me to understand multiple assignment operators

I can't figure out how it works! can someone help me why I get an output of 11 for variable c in the code below? var a = 10; var b = 3; var c = 2; c += a -= b -= c; document.write(a); // output: 9 document.write(b); // output: 1 document.write(c); // output: 11

12th Oct 2018, 6:35 PM
Bahamin Shahriari
Bahamin Shahriari - avatar
3 Respostas
+ 4
Read it from the right to the left: b -= c => b -= 2 => b = 1 a -= b => a -= 1 => a = 9 c += a => c += 9 => c = 11
12th Oct 2018, 6:54 PM
Anna
Anna - avatar
+ 1
Thanks! It's now make sense to me
12th Oct 2018, 6:58 PM
Bahamin Shahriari
Bahamin Shahriari - avatar
+ 1
You're welcome 🙂
12th Oct 2018, 6:58 PM
Anna
Anna - avatar