MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 123

Actionscript language reference
Table of Contents

Advertisement

Example
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);
trace(string1 === num);
// Automatic data typing in this example converts true to "1"
var string1:String = "1";
var bool1:Boolean = true;
trace(string1 == bool1);
trace(string1 === bool1);
// Automatic data typing in this example converts false to "0"
var string1:String = "0";
var bool2:Boolean = false;
trace(string1 == bool2);
trace(string1 === bool2);
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
// 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
See also
,
! (logical NOT)
,
(logical OR)
== (equality)
// true
// false
// true
// false
// true
// false
operator with the String class.
new
,
!= (inequality)
!== (strict inequality)
,
=== (strict equality)
,
,
&& (logical AND)
=== (strict equality)
||
123

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

This manual is also suitable for:

Flex

Table of Contents