
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Strict Equality and Inequality Operators
|
125
The inequality operator follows the same type conversion rules as the equality opera-
tor and always yields the opposite result, including when
NaN is used as an operand:
NaN != 7 // true
NaN != NaN // true!
In some languages, including Flash 4 ActionScript, the <> operator is used as the ine-
quality operator. Flash 4 used the deprecated
ne operator for string comparisons. In
Flash 5 and Flash MX, != should be used in lieu of
<> and ne for comparisons,
regardless of the operands’ datatypes. See also the logical NOT operator (
!) dis-
cussed later in this chapter.
Common Uses of Equality Operations
We’ll frequently use equality operations to form Boolean expressions within condi-
tional statements or to assign a Boolean value to a variable. Example 5-2 shows both
situations and demonstrates the
!= and == operators in action.
Experienced programmers will be quick to point out that we could have reduced if
(isWin = = true) to if (isWin), because
isWin holds a Boolean value, which is what the
if statement expects. While that’s quite right, it doesn’t make for a good example of
the equality operator, now does it? Furthermore, new programmers usually find the
more verbose form clearer. Both approaches are perfectly acceptable. We’ll cover this
topic ...