Web hosting india - 74Part IIJavaScript TutorialParameters (also known as arguments) provide

74Part IIJavaScript TutorialParameters (also known as arguments) provide a mechanism for handing off a value fromone statement to another by way of a function call. If no parameters occur in the function def- inition, both the function definition and call to the function have only empty sets of parenthe- ses (as shown in Chapter 5, Listing 5-8). When a function receives parameters, it assigns the incoming values to the variable namesspecified in the function definition s parentheses. Consider the following script segment: function sayHiToFirst(a, b, c) { alert( Say hello, + a); } sayHiToFirst( Gracie , George , Harry ); sayHiToFirst( Larry , Moe , Curly ); After the function is defined in the script, the next statement calls that very function, passingthree strings as parameters. The function definition automatically assigns the strings to vari- ables a, b, and c. Therefore, before the alert()statement inside the function ever runs, aevaluates to Gracie, bevaluates to George, and cevaluates to Harry. In the alert() statement, only the avalue is used and the alert readsSay hello, GracieWhen the user closes the first alert, the next call to the function occurs. This time through, different values are passed to the function and assigned to a, b, and c. The alert dialog boxreadsSay hello, LarryUnlike other variables that you define in your script, function parameters do not use the varkeyword to initialize them. They are automatically initialized whenever the function is called. Variable scopeSpeaking of variables, it s time to distinguish between variables that are defined outside andthose defined inside of functions. Variables defined outside of functions are called global vari- ables; those defined inside functions with the varkeyword are called local variables. A global variable has a slightly different connotation in JavaScript than it has in most otherlanguages. For a JavaScript script, the globe of a global variable is the current documentloaded in a browser window or frame. Therefore, when you initialize a variable as a globalvariable, it means that all script statements in the page (including those inside functions) have direct access to that variable value. Statements can retrieve and modify global variablesfrom anywhere in the page. In programming terminology, this kind of variable is said to haveglobal scopebecause everything on the page can see it. It is important to remember that the instant a page unloads itself, all global variables definedin that page disappear from memory forever. If you need a value to persist from one page toanother, you must use other techniques to store that value (for example, as a global variablein a framesetting document, as described in Chapter 16; or in a cookie, as described inChapter 18). While the varkeyword is usually optional for initializing global variables, Istrongly recommend you use it for all variable initializations to guard against future changesto the JavaScript language. In contrast to the global variable, a local variable is defined inside a function. You already sawhow parameter variables are defined inside functions (without varkeyword initializations). But you can also define other variables with the varkeyword (absolutely required for local
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision mysql hosting services