U-X > undefined

 

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.

When undefined is converted to a string, it converts to the empty string.

The value undefined is similar to the special value null. In fact, when null and undefined are compared with the equality operator, they compare as equal.

Example

In this 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 window. 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 window:

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

Note: In the ECMA-262 specification, undefined converts to the string "undefined", not the empty string. This is a difference between ActionScript and the ECMA-262 specification.