+ 1
How does the postfix y++ inside an equation (statement) work?
In JavaScript: What is the output of this code below and please explain it... How is this postfix working? var x=2; var y=1; y=x++; // y equals 2 or 3?? var z=x*y; document.write(z);
2 Respostas
+ 1
The output should be 6.
The statement "y=x++" makes y=2 and x=3. This is because y was assigned the "original" value of x, which was 2 and then x was incremented (x++).
Note that "y=x++" is totally different from "y=++x". If instead, "y=++x" was used in this code, y would then be assigned the value of x++, which is 3 and x would be incremented to 3 also. Which would give the output of 9 :]
+ 3
thank you very much!