• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 3. Understanding Variables > What Is a Variable?

What Is a Variable?

Your JavaScript programs will often need to store temporary values for use later in the script, in some other script, or even within an HTML form. For example, you might ask the user to enter her name when she first loads the page, and you could then use that name to personalize the page. Before you can do that, however, you first need to store the user's name in a safe place for later use. Similarly, if your script performs calculations, you might need to set aside a calculated value to use later. For example, if you're constructing a shopping cart script, you might need to calculate taxes on the order. To do that, you must first calculate the total value of the order, store that value, and then later take a percentage of it to work out the tax.

In programming, the way you save a value for later use is by storing it in a variable. This is a small chunk of computer memory that's set aside for holding program data. The good news is that the specifics of how the data is stored and retrieved from memory happen well behind the scenes, so it isn't something you ever have to worry about. As a scripter, working with variables involves just three things:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint