+ 1
Can some please explain me how.?
var x = 8; var y = x++ * 5; var z = y%x; document.write(z) 4 How?? From where the freaking 4 come. Please explain me what's going on here
4 Respuestas
+ 3
Struggling Alone
x++ is post increment which assign value first then increment x by 1 so
y = 8 * 5 and after assigning x = 9
So z = y % x = 40 % 9 = 4
+ 3
40%9 = 4 : you get reminder by %
Modula operator. (40-36=4)
40/9 = 4 : you get quotient by / division operator. (9*4=36)
45%9=0 , 45/9=5 since 9*5=45
+ 2
Ok... so it's like. First x which is 8 multiplied by 5 and become 40 then it incremented and x = 9 and y = 40
Then y (40) % x(9) = 3.6 or 4
If I'm not wrong so.
+ 1
Struggling Alone
There is difference between modulus operator (%) and division operator (/)