Things You'll Need:
- JavaScript editor
-
Step 1
Choose a variable name which meets JavaScript guidelines. Variables names can contain only numbers, letters, or underscores, and must start with a letter or underscore. The are case-sensitive: the variable
ABCis distinct fromabc. -
Step 2
Find the best place to declare your variable. Variables declared outside of a function are available to all commands throughout the entire script, and are called "global" while variables exclusive to a specific function are "local", declared inside the function.
-
Step 3
Declare the variable using the
var command, as follows:var my_variable; -
Step 4
Add additional variables to the declaration for compactness:
var one_var, two_var; -
Step 5
Specify an initial value for the variable by following it with an equal sign and the value:
var zero=0;











