I pulled this from scope and modify so that you can learn a bit more tricks. Check this example out.
<!DOCTYPE html>
<html>
<body>
<p>
In HTML, all global variables will become window variables.
</p>
<p id="demo"></p>
<script>
var apple=3;
var obj=new thing();
document.getElementById("demo").innerHTML =
"I can display " + window.apple + " and " + window.banana + " but not local " + window.orange + ". I can call this from getter though " + obj.getOrange();
function thing() {
banana=4;
var orange=5;
this.getOrange = function(){
return orange;
}
}
</script>
</body>
</html>
Output will look like this.
In HTML, all global variables will become window variables.
I can display 3 and 4 but not local undefined. I can call this from getter though 5
So unless you create the getter and setter for local variables, you will not be able to reference them. Global cariables will become window varaibles.