+ 8

Help can someone explain the line in var z in this code? I get confused. Thanks

What is the output of this code var a = 3; var b = 2; var z = (++b+a--)%5; document.write (z);

6th Jul 2017, 3:49 AM
RC Mon
RC Mon - avatar
2 odpowiedzi
+ 6
(++b+a--) results in 6 The ++b happens first which makes b equal to 3. Then b+a happens (3+3). The result of this is then used for the modulus 6%5 and z is set to 1. Then the -- of a sets a to 2.
6th Jul 2017, 4:04 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
z = (3 + 3)%5 z= 1 here in z ++b means that first increase b and than add and a-- means first add a and decrease the value of a . now value of a is 2 and value of b is 3.
6th Jul 2017, 3:56 AM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar