+ 5

Please explain this JS challenge...

What is the output of this code? var x = 8; var y = x++ * 5; var z = y % x; alert(z);

3rd Aug 2017, 10:35 PM
michael1403
michael1403 - avatar
2 Respostas
+ 4
Thanks! Output 4 is correct. So x++ only increments after x*5 is assigned to y. Is there a rule?
3rd Aug 2017, 10:50 PM
michael1403
michael1403 - avatar
+ 1
Yes. Examples: var x = 5; alert(x++); alert(x); // the output is 5 and 6 var x = 5; alert(++x); alert(x); // the output is 6 and 6
16th Dec 2017, 11:54 PM
Augustinas Lukauskas
Augustinas Lukauskas - avatar