Possible Duplicate:
++someVariable Vs. someVariable++ in Javascript
I am struggling to understand the increment operator. This operator increments (adds one to) its operand and returns a value. I have used it postfix with operator after operand (x++), so it returns the value before incrementing.
So if x is three, then the statement y = x++ sets y to 3 and increments x to 4
var x = 3;
var y = x++;
console.log(x); // 4
console.log(y); // 3
I am not understanding why y
does not hold a value of 4 and is instead set to 3, and why it is that x
holds a value of 4, when it was assigned a value of 3.