JavaScript Chapter 3




Skip to Chapter   1  2  3  4  5  6  7  8  9  10 

                                                              Chapter 3 -- Variables






What are variables?

Variables are magical words or letters that represent a number or another word.
FYI: The correct description of a variable is a named memory location... but no one wants to try to choke down that description.
Don't understand? Don't worry!
I'm going to give you a bunch of examples of variables in action. Please feel free to play around with the values of the variables(anything inside of double quotes).
If you screw up, don't worry, just click in the address bar, hit enter, and everything will return to normal.
First we tell the computer what name we want to set as a variable: var description;
Then we set the value for the variable. The value is the number or set of letters that the variable represents. In my example "fluffy!" was the value of the variable description.
After defining the variable, we use it: alert('My logic is '+description);





You are familiar with the alert function and that the stuff you want to show up in the alert box must be in quotes of some type. Therefore, the first thing that may jump out at you is that the variable is not in quotes this is how the computer is able to recognize that the word description is a variable.
There is always a semicolon(;) after any statement in javascript... Well, not always, but put them in always anyway.
Below is a list of the most important uses for variables:
Use variables to hold input gotten from the user (this would be used in a form).
You can also use variables to count the number of times a certain process is ran.
Another valued use for variables is to store information about an object on your page (that'll make sense in chapter 5 -- DHTML).
In the fourth chapter you get to use conditional statements; this allows you to actually use your variables!
Getting started DHTML Conditions