+ 2

Why the result is 7 ?

var x=7; var y=x++; var z=y++ % x; alert(z);

21st Jul 2019, 12:00 PM
Hjjko
2 Respuestas
+ 6
var x=7; var y=x++, y will be 7 and after this line x will become 8 var z=y++%x, y is still 7 here and x is 8, so 7%8 is 7, the post increment will work after that line, try print y and it will become 8, what happen there is operator precedence
21st Jul 2019, 12:24 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
Ok, thanks a lot
21st Jul 2019, 12:32 PM
Hjjko