Variables in JavaScript
Notes from April 6, 2005 class
A Variable represents or holds a value.
var variablename=variablevalue;
Variables
- are case-sensitive
- must begin with a letter or an underscore
- cannot contain spaces
- should avoid JavaScript's reserved words (words that have special meaning within JavaScript; check your textbook for a list of these)
If a variable is a string:
- it must be contained within matching double-quotes or single-quotes
- it is case-sensitive
Special characters:
This is translated by Javascript into this \\ \ \t tab \" " \n newline There are several other special characters. Check the textbook for the complete list.
Boolean operators
You can set a variable to either true (1) or false (0).
(We won't be using Boolean operators for a while, but I wanted to get the concept recorded into the class notes now.)