Variable Declaration (Definition)

Variable declarations are stored as properties in an object.

Availability:

ECMAScript edition - 2

To create a variable called myVariable, you need to place a declaration like this in the script source text:

var myVariable;

You can optionally assign an initial value to the variable as it is declared. Like this:

var myVariable = "Initial value";

The semantics of the ECMAScript standard dictate that variable declarations must follow Function Declarations and Formal Parameter List processing.

The initial value of variables as they are declared is set to undefined. Any attributes of the property in the variable object are defined by the type of code. If a variable already exists and a declaration duplicates the same identifying name, the present value will not be replaced by the undefined value. In particular, a variable declaration cannot replace a previously declared function definition or formal parameter name.

See also:Declaration, Definition, Formal Parameter List, function( ... ) ..., Script Source Text, var, Variable instantiation, Variable statement

Cross-references:

ECMA 262 edition 2 - section - 10.1.3

ECMA 262 edition 3 - section - 10.1.3

O'Reilly JavaScript Definitive Guide - page - 53