<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>
Related Scripts with Example Source Code in same category :