ITSE 1411 Beginning Web
JS Module 1 Discussion Variables
Discussion
- Variables
- You learned in math class that a variable was used to represent a value that could change (vary).
- In programming, a variable serves the same purpose but it is more than that. Data (or values) are
assigned to variables and these are stored in computer memory. In that sense, the variable name
is the name of the memory location where the value is stored. Compare this to your postal box.
It is quite common for neighborhoods and apartments to have a block of postal boxes. Each resident
is assigned to one and only one postal box. A variable name applies to one and only one memory
location.
- In programming, the term name is also called identifier. In HTML, there is both a name and an id attribute
for most tags. In programming, the term is used interchangeably.
- In many programming languages, there are 52 characters in the alphabet, not 26. This is true in
both HTML and JavaScript. An uppercase alphabetic character is not represented the same as a lowercase
alphabetic character. The book uses the explanation ASCII letter. This refers to the code that represents
all characters. The computer is a digital machine. Everything is represented as series of 0's and 1's.
This is called the binary number system. You are used to the digital number system. If you think
about it, this makes perfect sense. A computer is an electronic machine. It is either off or on. Unless
you had an accident, you have ten fingers. Computers have 2 states. People have 10.
- Rules for identifiers
- You may use all uppercase alphabetic characters, the dollar sign ($), or underscore(_).
If you stick with web programming, you will pick up multiple languages. There are
some languages (such as php) that require variable names to start with the dollar sign. For that
reason, I recommend that you do not use the dollar sign in JavaScript. To me it is
like saying "Adios monsieur". I like to keep things more organized because when I am
on a tight deadline, I need little triggers that keep me organized. And you will
eventually combine JavaScript and PHP on the same page.
- Numbers are allowed, but NEVER as the first character of the identifier.
- NEVER use a space in an identifier.
- Reserved words have a special meaning (reserved to do something specific). Therefore, you
cannot use a reserved word as an identifier. Page 31 of the text gives you a list of the
reserved words.