0

Modulo and post increment [solved]

Hi, I tried to understand why this code has an output of 7 but I don't get it. My solution would be 2 Can someone give me a hint? var x = 7; var y = x++; var z = y++ % x; alert(z);

15th Nov 2020, 9:28 AM
Sera_Sera_que
Sera_Sera_que - avatar
2 Respostas
+ 15
1)For y=x++, y will be 7 and after this line x will become 8. 2)For var z=y++%x, y is 7 here and x is 8, so 7%8 is 7, the postfix operator will increment after that line. 3)You can try printing y and it will become 8. This happens because of operator precedence. Try learning it from the course once again.
15th Nov 2020, 9:36 AM
Aditya
Aditya - avatar
15th Nov 2020, 9:39 AM
Sera_Sera_que
Sera_Sera_que - avatar