Ok! This post will be ever growing as I come across tricks used by the geek community to write code. I was always baffled by code which didn’t stick to the book. Hoping this post will clear out those myths that if you use this structure whilst coding, you are “god” of the geek land….maybe you are!!!..whatever.
Compound Assignment Operators:
Compound assignment operators provide two benefits. Firstly, they produce more compact code.Saves the trouble of over exercising those fingers. Secondly, the variable being operated upon, or operand, only needs to be evaluated once in the compiled application. This can actually make the code more efficient when executed.In contrast, the statement using the simple operators makes a copy of the variable A, performs the operation on the copy, and then assigns the resulting value back to A, temporarily using extra memory.
Lets take the case of arithmetic operators (+ – * / %).
var += expression; // var = var + expression
var -= expression; // var = var – expression
var *= expression; // var = var * expression
var /= expression; // var = var / expression
var %= expression; // var = var % expression
This statement adds 1 to value :
value ++;
This statement subtracts 1 from value :
value –;
You can use the increment and decrement operators (– and ++) either before or after the variable or property they operate upon. If used before the operand, they are called prefix operators. If used after the operand, they are called postfix operators.
var value :Number = 5;
trace(value ++); // 5
trace(value ); // 6
var value :Number = 5;
trace(++value ); // 6
trace(value ); // 6





