Published in August 28, 2009 by Bruno Sales
Posted in Uncategorized
Logic Operator ||= in AS3
Well, few people knows about the logic operator “||=”. I’ll try to explain a little more about it.
In the adobe documentation, this operator is described like: “Assigns expression1 the value of expression1 || expression2″. Just to remember, the sintaxe to logic operator is “expression1 operator expression2“.
I’ll show some examples of how it works.
Exemple1:
1 2 3 | var array:Array; // Variable arr is null. array ||= ["Bruno Sales"]; // In case array is null, assign the value ["Bruno Sales"] trace(array.toString()); // Result: New value assigned, trace prints "Bruno Sales" |
Exemple2:
1 2 3 | var array:Array = ["DClick"]; // Variable arr has the value ["DClick"]. array ||= ["Bruno Sales"]; // In case array is null, assign the value ["Bruno Sales"] trace(array.toString()); // Result: No value assigned, trace prints "DClick" |
Soon, looking the difference of this 2 exemples, we conclued that the logic operator “||=” makes the same thing of the code below, but in a better way.
1 2 3 4 5 |
I hope you all liked it.

No comments yet
Leave a Comment