Cedant web hosting - 75Chapter 7Programming Fundamentals, Part IIvariables or they become

75Chapter 7Programming Fundamentals, Part IIvariables or they become recognized as global variables). The scope of a local variable isonly within the statements of the function. No other functions or statements outside of func- tions have access to a local variable. Local scopeallows for the reuse of variable names within a document. For most variables, Istrongly discourage this practice because it leads to confusion and bugs that are difficult totrack down. At the same time, it is convenient to reuse certain kinds of variable names, suchas forloop counters. These are safe because they are always reinitialized with a startingvalue whenever a forloop starts. You cannot, however, nest one forloop inside anotherwithout specifying a different loop counting variable in the nested loop. To demonstrate the structure and behavior of global and local variables and show you whyyou shouldn t reuse most variable names inside a document Listing 7-2 defines two globaland two local variables. I intentionally use bad form by initializing a local variable that hasthe same name as a global variable. Listing 7-2:Global and Local Variable Scope Demonstration When the page loads, the script in the Head portion initializes the two global variables (aBoyand hisDog) and defines the demo()function in memory. In the Body, another script beginsby invoking the function. Inside the function, a local variable is initialized with the same nameas one of the global variables hisDog. In JavaScript, such a local initialization overrides theglobal variable for all statements inside the function. (But note that if the varkeyword is leftoff of the local initialization, the statement reassigns the value of the global version to Gromit. ) Another local variable, output, is merely a repository for accumulating the text that is to bewritten to the screen. The accumulation begins by evaluating the local version of the hisDogvariable. Then it concatenates some hard-wired text (note the extra spaces at the edges ofthe string segment). Next comes the evaluated value of the aBoyglobal variable any global
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services