scope , . .
<!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>
.
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
Therefore, unless you create getter and setter for local variables, you cannot reference them. Global Caribbean will become window variable.
source
share