Syntax: Variables
Variables are containers of information and should be declared (i.e. defined) before you use them. Variables can also be initialised when they are declared. To declare and/or initialise a variable use the var statement.
var variableName = value
variableName - is the name you want to give to the variable. The name must begin with a letter but can contain numeric characters. A name cannot contain spaces, use the _ character if you want to space out a variable name e.g. my_first_name.
value – is the contents of the variable.
Advanced:
When var is used inside a function, it makes the variable local to the function. This means that the variable cannot be used outside the function. If a variable is used without a var declaration, the variable is a property of the page and can be used outside the function or in a different function. Unless you specifically want this to happen, it is probably a bad thing to do, and hence var should be used.
Outside a function var has no effect at all. All variables outside of functions are properties of the page.