0
i have got different value when i++ is before the statement and when i++ is after the statement
var i = 0; while ( i<=5) { document.write(i + "<br />"); i++; } outputs = 0,1,2,3,4,5 var i = 0; while ( i<=5) { i++; document.write(i + "<br />"); } outputs 1, 2 , 3, 4, 5, 6. why are the results different?
3 Réponses
+ 9
In the first case you increment i after you display it. So it starts at 0 since i is defined as 0.
In the second case i is incremented before you display it, so when you call document.write() it is at 0+1 = 1. It then starts at 1.
+ 7
Yes much like it.
0
okay thanks you very much. is
it like.
var x = 3;
document.write(x++);
outputs 3.
var x = 3;
x++;
document.write(x);
outputs 4.