S
shamilton72
If I use the following JavaScript code:
var x=3;
var y=2;
document.write(x + y + (x++));
it gives an answer of 8 which I thought would be incorrect as the
post-increment is in brackets. However, if I change the write statement
to
document.write((x++) + x + y);
it gives in my opinion the correct answer of 9.
Is there any reason for this?
Cheers,
Sarah
var x=3;
var y=2;
document.write(x + y + (x++));
it gives an answer of 8 which I thought would be incorrect as the
post-increment is in brackets. However, if I change the write statement
to
document.write((x++) + x + y);
it gives in my opinion the correct answer of 9.
Is there any reason for this?
Cheers,
Sarah