How to declare variables
without assigning values to them
var subtotal;
// declares a variable named subtotal
var lastName, state, zipCode;
// declares three variables
The assignment operators
=
+=
-=
*=
/=
%=
How to declare variables and assign values
var subtotal = 74.95; // subtotal is 74.95
var salesTax = subtotal * .1; // salesTax is 7.495
var isValid = false; // Boolean value is false
var zipCode = "93711", state = "CA";
// two assignments
var firstName = "Ray", lastName = "Harris";
var fullName = lastName + ", " + firstName;
// fullName is "Harris, Ray"
How to code compound assignment statements
var subtotal = 24.50;
subtotal += 75.50; // subtotal is 100
subtotal *= .9; // subtotal is 90 (100 * .9)
var firstName = "Ray", lastName = "Harris";
var fullName = lastName; // fullName is "Harris"
fullName += ", "; // fullName is "Harris, "
fullName += firstName; // fullName is "Harris, Ray"
var months = 120, message = "Months: ";
message += months; // message is "Months: 120"