In JavaScript you can use ++
operator before (pre-increment) or after the variable name (post-increment). What, if any, are the differences b
++x
increments the value, then evaluates and stores it.x++
evaluates the value, then increments and stores it.var n = 0, m = 0;
alert(n++); /* Shows 0, then stores n = 1 */
alert(++m); /* Shows 1, then stores m = 1 */
Note that there are slight performance benefits to using ++x
where possible, because you read the variable, modify it, then evaluate and store it. Versus the x++
operator where you read the value, evaluate it, modify it, then store it.