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

Variables

A variable is a block of memory reserved to hold some value that may change from time to time. You can think of it as a mailbox with a name on it; the mailbox holds a slip of paper with information written on it. Let’s say you need to keep track of the current width of a rectangle and need to store a changeable message; in ECMA Script you define these variables like this:

var currentWidth;
var message;

You may visualize them as shown in Figure C-1.

Two empty variables
Figure C-1. Two empty variables

Variables defined this way have nothing in their “mailbox;” the technical term is that these variables contain the null value. Variable names must start with a letter or an underscore and can contain only letters, digits, and underscores. They are case sensitive, so width, Width, and WIDTH are names of three different variables.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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