Global and Local Variable Scope Demonstration : Variable Definition : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » Variable Definition »

 

Global and Local Variable Scope Demonstration




<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var globalVar = "Boy"   // global
var globalVar2 = "dog"        // global
function demo() {
    var globalVar2 = "cat"    // local version of globalVar2
    var output = globalVar2 + " does not belong to " + globalVar + ".<BR>"
    document.write(output)
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
demo();
document.write(globalVar2 + " belongs to " + globalVar + ".")
</SCRIPT>
</BODY>
</HTML>


           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» Variable Definition