I know that in C, C++, Java, etc, there is a difference between foo++ and ++foo. In JavaScript, there is no ++foo, and JavaScript's foo++ usually behaves like C's ++foo:
var x = 10;
x++;
console.log(x); //11
But here:
var x = 0;
var w = "012345";
console.log(w[x++]); //0
console.log(w[x++]); //1
...It behaves like C's foo++?
++is a Postfix Increment Operator. When placed before a unary expression, it's a Prefix Increment Operator.--is the equivalent prefix/postfix decrement operator. Neither are unary operators.JavaScript's foo++ usually behaves like C's ++foo- I think you made a mistake in this statement ... the correct version is JavaScript's foo++ never behaves like C's ++foo - or alternatively JavaScript's foo++ always behaves like C's foo++console.log(x++)you will get10not11- post-increment doesn't wait until an arbitrary time later to change x within the statement it is executed ... which isx++x++logs 0, then increments x. Then it logs 1 and increments x again (so next time it will be 2). Prefix increment means increment, then evaluate the expression. Posfix increment means evaluate the expression, then increment. In both cases, the value is incremented before the next expression is evaluated. The difference is the value used in the expression involving the operator.