Think of a variable as a container that you can place any literal values into, or assign it to represent an object that you have created. The variable value can be changed or have operations performed on them. Every variable you create in Javascript is associated to an object or data type that you can access the properties and methods of.
Javascript CODE EXAMPLE
<script type="text/javascript">
var a = 5;
var b = 3;
var c = a + b;
document.write("Answer to the problem is: " + c);
document.write("<hr / >");
var person1 = "Bill";
var person2 = "Sara";
var myText = person1 + " went on a date with " + person2;
document.write(myText);
</script>
Alter a variable's value at any point in your script:
Javascript CODE EXAMPLE
var a = 5; // initialize the variable near the top of script
a = 10; // alter the variable value any time you need to in script
Variables can also represent Javascript objects you might work with.
Javascript CODE EXAMPLE
<script type="text/javascript">
var now = new Date();
document.write(now);
</script>