Overview

Variables are the corner stone of most if not all programming languages. When dealing with data a program will store it somewhere and in order to get it back it is given a name. A lot of languages are whats called strongly typed, this means the type of data that can be stored in a particular named place is always the same for example in Java the code int aVariable; means that the named storage container aVariable can only ever be used to store a number.

Lets declare and use a few variables, the structure is always the same for declaring variables in JavaScript: var <<variable name>>; will declare a variable.

you store something in a variable using the = sign for example:aVariable = 3;

and you get the contents of a variable by simply giving its name: aVariable

putting this all together and the lines:var aVariable = 3;
var anotherVariable = aVariable + 1;
will result in two new variables being created aVariable that contains the value 3 and anotherVariable that contains the number 4, note I slipped in some simple arithmetic here but its no biggy :)

just stick this code into the test.html file where it says //PLACE CODE HERE, et voila!

    function start() {
	var aVariable = 11;
	var newVariable = 32;
	var whatAmI = aVariable + newVariable;
    }
   
What is the value of the variable whatAmI?

Ok, so I'll be the first to admit thats a boring program try this to see if you were right

    function start() {
	var aVariable = 11;
	var newVariable = 32;
	var whatAmI = aVariable + newVariable;
	document.write( "the value is " + whatAmI );
    }
   

What do you think the result to this one will be?

    function start() {
	var aVariable = 11;
	var newVariable = 32;
	aVariable = aVariable + 1;
	var whatAmI = aVariable + newVariable;
	document.write( "the value is " + whatAmI );
    }
   

Next Some examples