+ 2

why it ouputs 2.5? js. Explain the line var z=x++/y%4;

<script> var x=5; var y=2; var z=x++/y%4; document.getElementById("test").innerHTML = z; </script> output: 2.5

12th Jun 2020, 11:22 AM
Sujithra
3 Réponses
+ 2
5/y%4 5/2 =2.5 and 2.5%4=2.5 here x is incremented afterwards ,if you print x it will be 6 now
12th Jun 2020, 11:30 AM
Abhay
Abhay - avatar
+ 3
Thank you Abhay 🎉🎊
12th Jun 2020, 11:55 AM
Sujithra
+ 2
Sujithra let x=0 & y=1 y=x++; //y=0 x=1 y=++x; // y=1 x=1
12th Jun 2020, 3:11 PM
Ajitha G R
Ajitha G R - avatar