182 Syntax and Language Fundamentals
About using operators with strings
Comparison operators compare strings only if both operands are strings. An exception to this
rule is the strict equality (
===) operator. If only one operand is a string, ActionScript converts
both operands to numbers and performs a numeric comparison on them. For more
information on numeric operators, see “Using numeric operators” on page 188.
Except for the equality operator (
==), comparison operators (>, >=, <, and <=) affect strings
differently than when they operate on other values.
Comparison operators compare strings to determine which is first alphabetically. Strings with
uppercase characters precede strings that are lowercase. That means that "Egg" comes before
"chicken".
var c:String = "chicken";
var e:String = "Egg";
trace(c < e); // false
var riddleArr:Array = new Array(c, e);
trace(riddleArr); // chicken,Egg
trace(riddleArr.sort()); // Egg,chicken
<=
Less than or equal to Left to right
>
Greater than Left to right
>=
Greater than or equal to Left to right
==
Equal Left to right
!=
Not equal Left to right
&
Bitwise AND Left to right
^
Bitwise XOR Left to right
|
Bitwise OR Left to right
&&
Logical AND Left to right
||
Logical OR Left to right
?:
Conditional Right to left
=
Assignment Right to left
*=, /=, %=, +=, -
=, &=, |=, ^=,
<<=, >>=, >>>=
Compound assignment Right to left
,
Comma Left to right
Lowest precedence
Operator Description Associativity