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:
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:
var array:Array = ["redspark"]; // Variable arr has the value ["redspark"].
array ||= ["Bruno Sales"]; // In case array is null, assign the value ["Bruno Sales"]
trace(array.toString()); // Result: No value assigned, trace prints "redspark"
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.
var array:Array = ["redspark"];
if (array == null)
{
array = ["Bruno Sales"];
}
I hope you all liked it. 🙂