Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 54

Programming actionscript 3.0
Table of Contents

Advertisement

An interesting implication of the lack of block-level scope is that you can read or write to a
variable before it is declared, as long as it is declared before the function ends. This is because
of a technique called hoisting, which means that the compiler moves all variable declarations
to the top of the function. For example, the following code compiles even though the initial
function for the
trace()
trace(num); // NaN
var num:Number = 10;
trace(num); // 10
The compiler will not, however, hoist any assignment statements. This explains why the
initial
of
trace()
num
of the Number data type. This means that you can assign values to variables even before they
are declared, as shown in the following example:
num = 5;
trace(num); // 5
var num:Number = 10;
trace(num); // 10
Default values
A default value is the value that a variable contains before you set its value. You initialize a
variable when you set its value for the first time. If you declare a variable, but do not set its
value, that variable is uninitialized. The value of an uninitialized variable depends on its data
type. The following table describes the default values of variables, organized by data type:
Data type
Boolean
int
Number
Object
String
uint
Not declared (equivalent to type annotation
All other classes, including user-defined classes.
For variables of type Number, the default value is
defined by the IEEE-754 standard to mean a value that does not represent a number.
54
ActionScript Language and Syntax
variable happens before the
num
results in
(not a number), which is the default value for variables
NaN
variable is declared:
num
Default value
false
0
NaN
null
null
0
)
undefined
*
null
(not a number), which is a special value
NaN

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents