View comments | RSS feed

undefined

Availability

Flash Player 5.

Usage

undefined

Parameters

None.

Returns

Nothing.

Description

A special value, usually used to indicate that a variable has not yet been assigned a value. A reference to an undefined value returns the special value undefined. The ActionScript code typeof(undefined) returns the string "undefined". The only value of type undefined is undefined.

In files published for Flash Player 6 or earlier, the value of undefined.toString() is "" (an empty string). In files published for Flash Player 7 or later, the value of undefined.toString() is undefined.

The value undefined is similar to the special value null. When null and undefined are compared with the equality (==) operator, they compare as equal. However, when null and undefined are compared with the strict equality (===) operator, they compare as not equal.

Example

In the following example, the variable x has not been declared and therefore has the value undefined. In the first section of code, the equality operator (==) compares the value of x to the value undefined, and the appropriate result is sent to the Output panel.In the second section of code, the equality (==) operator compares the values null and undefined.

// x has not been declared
trace("The value of x is "+x);
if (x == undefined) {
   trace("x is undefined");
} else {
   trace("x is not undefined");
}
trace("typeof (x) is "+typeof (x));
if (null == undefined) {
   trace("null and undefined are equal");
} else {
   trace("null and undefined are not equal");
}

The following result is displayed in the Output panel.

The value of x is undefined
x is undefined
typeof (x) is undefined
null and undefined are equal

Comments


Fumio Nonaka said on Sep 20, 2004 at 11:09 AM :
[Description]
The 'undefined' does not have the 'toString()' method. So,
undefined.toString should return 'undefined'.
•Wrong:
In files published for Flash Player 6 or earlier, the value of
undefined.toString() is "" (an empty string). In files published for Flash
Player 7 or later, the value of undefined.toString() is undefined.
•Correct:
In files published for Flash Player 6 or earlier, the value of
String(undefined) is "" (an empty string). In files published for Flash
Player 7 or later, the value of String(undefined) is "undefined".

It would be better to be mentioned about evaluated value of 'undefined'
as number, Number(undefined). It is 0 in Flash Player 6 and NaN in
Flash Player 7.
Francis Cheng said on Oct 15, 2004 at 10:55 AM :
Thanks Fumio, I've made the correction to the source file and I've added a paragraph about Number(undefined).
mspres said on Dec 12, 2004 at 5:05 PM :
Is it better to myVar=undefined or delete myVar?
No screen name said on Apr 6, 2005 at 6:57 AM :
when I use this code in old FLASH MX (6) it's work
but in FLASH MX 2004 (7) it's not working.

on (release) {
if ( x == undefined) {
x = "defined";
} else {
x = undefined;
}
}

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001866.html