+ 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

19th Jun 2021, 5:17 PM
Khilesh Dewangan
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
19th Jun 2021, 5:19 PM
A͢J
A͢J - avatar
+ 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
19th Jun 2021, 6:05 PM
Jayakrishna 🇮🇳
+ 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.
19th Jun 2021, 5:34 PM
Khilesh Dewangan
+ 1
Struggling Alone There is difference between modulus operator (%) and division operator (/)
19th Jun 2021, 6:16 PM
A͢J
A͢J - avatar