Initialization (Definition)

Setting a variable to its initial condition.

Initialization code is very similar to assignment statements in the main body of the code. There is a slight difference in that the assignment takes place before any code is executed.

If variables are not initialized they will contain the value undefined.

The initialization happens when the variable is declared using the var keyword.

Objects are initialized when they are constructed. This is a somewhat different process to that of initializing a variable.

If a variable is initialized to equal an object, it is really a reference to that object and not the object itself that gets stored in the variable.

See also:Constant expression, Declaration, var