March 2012
Beginner
432 pages
10h 15m
English
Variables in JavaScript, as in most languages, can be thought of as named “buckets” that associate names with data that can be used in a program. Information for different variables is stored in memory, which allows you to access that information with a name that points to those data in memory. For example, if you were writing a program that would convert degrees in Fahrenheit to degrees in Celsius, you might store the degrees in a variable in order to do multiple calculations on it.
Listing 2–2. Simple JavaScript Variables
var degrees = 51;
var celsius = (degrees - 32) * 5 / 9;
console.log(degrees);
console.log(degrees * 2);
console.log(celsius);
Figure 2–6. Firebug variables
JavaScript variables must begin with a letter, ...
Read now
Unlock full access