User Guide

Using operators to manipulate values in expressions 37
Equality operators
You can use the equality (
==) operator to determine whether the values or references of two
operands are equal. This comparison returns a Boolean (
true or false) value. If the operands are
strings, numbers, or Boolean values, they are compared by value. If the operands are objects or
arrays, they are compared by reference.
It is a common mistake to use the assignment operator to check for equality. For example, the
following code compares x to 2:
if (x == 2)
In that same example, the expression if (x = 2) would be incorrect, because it doesnt compare
the operands; it assigns the value of 2 to the variable
x.
The strict equality (
===) operator is similar to the equality operator, with one important
difference: The strict equality operator does not perform type conversion. If the two operands are
of different types, the strict equality operator returns
false. The strict inequality (!==) operator
returns the opposite of the strict equality operator.
The following table lists the ActionScript equality operators:
Assignment operators
You can use the assignment (
=) operator to assign a value to a variable, as shown in the
following example:
var password:String = "Sk8tEr";
You can also use the assignment operator to assign multiple variables in the same expression. In
the following statement, the value of
d is assigned to the variables a, b, and c:
a = b = c = d;
You can also use compound assignment operators to combine operations. Compound operators
perform on both operands and then assign the new value to the first operand. For example, the
following two statements are equivalent:
x += 15;
x = x + 15;
The assignment operator can also be used in the middle of an expression, as shown in the
following example:
// If the flavor is not vanilla, output a message.
if ((flavor = getIceCreamFlavor()) != "vanilla") {
trace ("Flavor was " + flavor + ", not vanilla.");
}
Operator Operation performed
==
Equality
===
Strict equality
!=
Inequality
!==
Strict inequality