If you have done any programming before you know that variables play an important part. Variables allow the script to store information gathered or computed in one part of a program and then be used in another part of the script. Inprogramminbefore you
can use a variable you must define it. In Java Script, variables can be defined by using the
var command or by when they are first called. Variables also are not global, they only work in the section of the program that are defined in, when
you learn about functions you will learn that you must pass variables on to the function. Variables must start with a letter or an underscore. You can also not use any reserved words. Reserved words are words that are commands built-in objects or meth
ods. To define a name variable you would say
var name. Lets take the name Smith. We want to store that word or string in variable called name.
Note: Words are known as strings, Strings are a type of variable. there are two types of variables, numbers and text strings. Textstrings are enclosed in quotes and numbers are values stored in the variable.
To store the varaible we would use the command
varname="smith". After storing the variable we want to then display it on the screen. We can then use the
Note: the name of the variable in
document.wirte(name) is not in quotes if it were then only name would be printed and not smith.
Our Script would look like whats below.
Here is the result of the above script