JavaScript Variables
A variable is a "container" for information you want
to store.
Examples
Variable Variables are used to store data. This
example will show you how.
Variables
A variable is a "container" for information you want to store. A
variable's value can change during the script. You can refer to a
variable by name to see its value or to change its value.
Rules for Variable names:
- Variable names are case sensitive
- They must begin with a letter or the underscore character
Declare a Variable
You can create a variable with the var statement:
You can also create a variable without the var statement:
Assign a Value to a Variable
You assign a value to a variable like this:
Or like this:
The variable name is on the left side of the expression and the
value you want to assign to the variable is on the right. Now the
variable "strname" has the value "Hege".
Lifetime of Variables
When you declare a variable within a function, the variable can
only be accessed within that function. When you exit the function,
the variable is destroyed. These variables are called local
variables. You can have local variables with the same name in
different functions, because each is recognized only by the function
in which it is declared.
If you declare a variable outside a function, all the functions
on your page can access it. The lifetime of these variables starts
when they are declared, and ends when the page is closed.
Product Spotlight
Hosting Spotlight
Phone Cards
Phone Cards Online
International and domestic phone cards for US customers.
Great affiliate program.
We Help You For Free. You Can Help Us!
Jump to: Top of Page or HOME or Printer
friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Google Yahoo Alta Vista MSN Lycos Excite Ask Jeeves HotBot
W3Schools is for training only. We do not warrant the correctness
of the content. The risk of using it remains entirely with the user.
While using this site, you agree to have read and accepted our terms of
use and privacy
policy.
Copyright
1999-2004 by Refsnes Data. All Rights Reserved.
|