I got this simple piece of code:
var x=10;
var y=8;
x -= y += 9;
alert(x+" and "+y);
The result will be "-7 and 17".
Why does JavaScript executes the y +=9 before the x -= y?
Operator precedence determines the way in which operators are parsed with respect to each other. Operators with higher precedence become the operands of operators with lower precedence
Associativity determines the way in which operators of the same precedence are parsed.
Since -= and += are right associative therefore they are evaluated from right to left.
Hence y +=9 gets evaluated first.
-=and+=are right associative operators and this are evaluated right-to-left.