User Guide
Using operators to manipulate values in expressions 53
String operators
The addition (+) operator has a special effect when it operates on strings: It concatenates the two
string operands. For example, the following statement adds
"Congratulations," to "Donna!":
"Congratulations, " + "Donna!"
The result is "Congratulations, Donna!" If only one of the addition (+) operator’s operands is
a string, Flash converts the other operand to a string. ActionScript treats spaces at the beginning
or end of a string as a literal part of the string.
The comparison operators
>, >=, <, and <= also have a special effect when operating on strings.
These operators compare two strings to determine which is first in alphabetical order.
The comparison operators compare strings only if both operands are strings. If only one of
the operands is a string, ActionScript converts both operands to numbers and performs a
numeric comparison. Uppercase characters precede lowercase in alphabetic order, so “Eagle”
comes before “dog.” If you want to compare two strings or characters regardless of case, you need
to convert both strings to upper- or lowercase before comparing them.
Logical operators
Logical operators compare Boolean values (
true and false) and return a third Boolean value.
For example, if both operands evaluate to
true, the logical AND (&&) operator returns true. If
one or both of the operands evaluate to
true, the logical OR (||) operator returns true. Logical
operators are often used with comparison operators to determine the condition of an
if
statement. For example, in the following script, if both expressions are true, the
if statement will
execute and the
myFunc() function will be called:
if (i > 10 && i <50){
myFunc(i);
}
<=
Less than or equal to: Returns true if the left operand is mathematically smaller than
or the same as the right operand.
Returns
true if the left operand alphabetically precedes or is the same as the right
operand.
>=
Greater than or equal to: Returns true if the left operand is mathematically larger than
or the same as the right operand.
Returns
true if the left operand alphabetically follows or is the same as the right
operand.
<>
!=
Not equal: Returns
true if the operands are not mathematically equivalent.
Returns
true if the operands are not the same.
== Equality: Tests two expressions for equality. The result is true if the expressions are
equal.
=== Strict equality: Tests two expressions for equality; the strict equality operator performs
the same as the equality operator except that data types are not converted. The result
is
true if both expressions, including their data types, are equal. Does not apply to
strings.
Operator Operation performed