
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Logical Operators
|
135
The technical behavior of the logical AND operator is quite similar to that of the log-
ical OR operator. First, operand1 is converted to a Boolean. If the result of that con-
version is
false, the value of operand1 is returned. If the result of that conversion is
true, the value of operand2 is returned.
If the first operand in a logical AND operation resolves to
false, it is unnecessary,
and therefore inefficient, to evaluate the second operand. Therefore, ActionScript
evaluates the second operand only if the first operand resolves to
true. This fact is
useful in cases in which you don’t want to resolve the second operand unless the first
operand resolves to
true. In this example, we perform the division only if the divisor
is nonzero:
if (numItems != 0 && total / numItems > 3) {
trace("You've averaged more than 3 dollars per transaction");
}
Logical NOT
The logical NOT operator (!) returns the Boolean opposite of its single operand. It
takes the general form:
!operand
where operand can be any legal expression. If operand is true, logical NOT returns
false.Ifoperand is false, logical NOT returns true.Ifoperand is not a Boolean, its
value is converted to a Boolean for the sake of the operation and its opposite is
returned.
Like the does-not-equal operator (
!=), the