Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript language elements > Operators > === strict equality operator | |||
expression1 === expression2
Tests two expressions for equality; the strict equality (===)operator performs in the same way as the equality (==) operator, except that data types are not converted. The result is true if both expressions, including their data types, are equal.
The definition of equal depends on the data type of the parameter:
Availability: ActionScript 1.0; Flash Player 6
expression1 : Object - A number, string, Boolean value, variable, object, array, or function.
expression2 : Object - A number, string, Boolean value, variable, object, array, or function.
Boolean - The Boolean result of the comparison.
The comments in the following code show the returned value of operations that use the equality and strict equality operators:
// Both return true because no conversion is done var string1:String = "5"; var string2:String = "5"; trace(string1 == string2); // true trace(string1 === string2); // true // Automatic data typing in this example converts 5 to "5" var string1:String = "5"; var num:Number = 5; trace(string1 == num); // true trace(string1 === num); // false // Automatic data typing in this example converts true to "1" var string1:String = "1"; var bool1:Boolean = true; trace(string1 == bool1); // true trace(string1 === bool1); // false // Automatic data typing in this example converts false to "0" var string1:String = "0"; var bool2:Boolean = false; trace(string1 == bool2); // true trace(string1 === bool2); // false
The following examples show how strict equality treats variables that are references differently than it treats variables that contain literal values. This is one reason to consistently use String literals and to avoid the use of the new operator with the String class.
// Create a string variable using a literal value
var str:String = "asdf";
// Create a variable that is a reference
var stringRef:String = new String("asdf");
// The equality operator does not distinguish among literals, variables,
// and references
trace(stringRef == "asdf"); // true
trace(stringRef == str); // true
trace("asdf" == str); // true
// The strict equality operator considers variables that are references
// distinct from literals and variables
trace(stringRef === "asdf"); // false
trace(stringRef === str); // false
! logical NOT operator, != inequality operator, !== strict inequality operator, && logical AND operator, || logical OR operator, == equality operator
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001302.html