0

could anybody help to explain the following code result? thanks

What is the output of this code? function x(y) { y++; y=y+2; ++y; y=y%3; return y; } document.write(x(3));

3rd Dec 2016, 2:19 PM
Welly Wei
Welly Wei - avatar
2 Réponses
+ 3
Result is 1.
3rd Dec 2016, 2:32 PM
Midhun Mathew
+ 1
replace y in the function with 3 and follow the code flow. first 3 is incremented to 4 then 2 is added to it then it's incremented to 7 . 7%3 = 1 . because % operator returns the remainder of 7%3.
3rd Dec 2016, 3:11 PM
Bahhaⵣ
Bahhaⵣ - avatar