views:

44

answers:

2
var btn:Button;
if(btn != null  &&  btn.label != '') {
      mx.controls.Alert.show("d");  
}

In the above if clause, is it guaranteed that the first condition(btn != null) will be evaluated before the second condition?

+4  A: 

Yes - ActionScript performs appropriate short-circuiting for the && operator:

So not only will it evaluate the expressions in the order you described, it won't bother evaluating the second expression at all if the first one returns false (which is as important a detail as the order of evaluation).

Just as a note, ActionScript also supports short-circuiting the logical or operator (||).

Michael Burr
+1  A: 

Yes it is. Excerpts from the Adobe livedocs regarding && operator:

&& logical AND Operator:

Usage:

  expression1 && expression2

Returns expression1 if it is false or can be converted to false, and expression2 otherwise.

Amarghosh