The var and function are declaration statements—they declare
or define variables and functions. These statements define
identifiers (variable and function names) that can be used elsewhere
in your program and assign values to those identifiers.
Declaration statements don’t do much themselves, but by creating
variables and functions they, in an important sense,
define the meaning of the other statements in your program.
var
The var statement declares a variable or variables. Here’s the
syntax:
var name_1 [ = value_1] [ ,..., name_n [= value_n]]
The var keyword is followed by a comma-separated list of variables
to declare; each variable in the list may optionally have
an initializer expression that specifies its initial value. For
example:
var i; // One simple variable
var j = 0; // One var, one value
var p, q; // Two variables
or define variables and functions. These statements define
identifiers (variable and function names) that can be used elsewhere
in your program and assign values to those identifiers.
Declaration statements don’t do much themselves, but by creating
variables and functions they, in an important sense,
define the meaning of the other statements in your program.
var
The var statement declares a variable or variables. Here’s the
syntax:
var name_1 [ = value_1] [ ,..., name_n [= value_n]]
The var keyword is followed by a comma-separated list of variables
to declare; each variable in the list may optionally have
an initializer expression that specifies its initial value. For
example:
var i; // One simple variable
var j = 0; // One var, one value
var p, q; // Two variables