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);
2 Antworten
+ 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.
+ 1
https://code.sololearn.com/WcT4XtoaT30J/?ref=app Got it, Thank you