JavaScript variables are containers for storing data values.
In this example, x
, y
, and z
, are variables:
var x = 5;
var y = 6;
var z = x + y;
From the example above, you can expect:
In this example, price1
, price2
, and total
, are variables:
var price1 = 5;
var price2 = 6;
var total = price1 + price2;
In programming, just like in algebra, we use variables (like price1) to hold values.
In programming, just like in algebra, we use variables in expressions (total = price1 + price2).
From the example above, you can calculate the total to be 11.