Variables contain values
Variables contain literal values.
Variable names can use letters, underscores, or dollar signs($), or numbers (but they can't start with a number!);
Declare your variables with the var keyword (for now).
If variables are not initialized they might be NULL.
<script type="text/javascript">
var myNum; //the variable called 'myNum' is declared but has no value in it (NULL)
myNum = 1; //the variable called 'myNum' is initialized to the literal value of 1
var myNum = 1; //you can declare and initialize a variable all in one line
var myOtherNum = myNum;
var myString = "hello";
var myString = hello; //why do you think we have to use quotes when you declare string variables????
var myBoolean = true;
</script>
Variable Types (there are more, but we'll start with these):
Integer
Number
String
Boolean
Variable assignment goes from right to left.
Unlike many languages, javascript is loosely-typed
String myString = "Hello"; //Java requires that you specify the type when you declare a variable.
In JavaScript you can specify the type when you declare a variable...
var myNum = new Number();
var someButton = document.getElementById("myButton");