Gotcha: using shorthand notation with boolean operators

Scris de in data de 26 March 2010
0 comentarii

In ActionScript (as well as JavaScript), the boolean AND and OR operators have a special meaning. That is, they don’t necessary return true or false, but return one of the operands. var op1:Boolean = true; var op2:int = 2; var op3:Object = null; var result_1or2:Object = op1 || op2; trace(result12); // output: true var result_1and2:Object = op1 && op2; trace(result); // output: 2 var result_3or2:Object = op3 || op2; trace(result); // output: 2 var result_3and2:Object [...] Citeşte mai mult »