
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Null
|
109
Null
Intellectually, the null type is nearly identical to the undefined type. Like the unde-
fined datatype, the null datatype is used to represent a lack of data and has only one
legal value, the primitive value
null. However, the null value is not assigned by the
interpreter automatically; it must be assigned by us deliberately.
We assign
null to a variable, array element, or object property to indicate that the
specified data container does not contain a legal number, string, Boolean, array, or
object value. For example, we might assign an initial value of
null to an object prop-
erty to indicate that it exists but has not yet been assigned a useful value.
To remove a variable or object property, you should use the delete operator rather
than assigning the value
null to the variable or property.
Note that
null compares equal only to itself and undefined:
null = = undefined; // true
null = = null; // true
To guarantee that a variable or property contains null (rather than undefined), check
its datatype using the typeof operator:
var x = null;
if (typeof x = = "null") {
trace("x is null");
}
Alternatively, as of Flash Player 6, we can use the strict equality operator (===), as
follows:
if (x = = = null) {
trace("x is null");
}
Though null and undefined are similar, their roles in ActionScript ...