Variables are declared using the keyword “var”. For instance, the following statement creates a variable named “message”:
message holds the value “undefined” because no initial value is assigned to it. To notice that, if a variable is undeclared, it’s also undefined.
However, an undeclared variable is different from an variable holding “undefined” value. Trying to use un undeclared variable may cause exceptions.
Variable is defined at where “var” statement is executed. Do not access a variable declared afterwards because at that point, the variable isn’t available yet.
It’s noteworthy that assigning value to an undeclared variable accidentally creates a variable in the global scope.