In local scope, the variable is defined within a particular function. The simplest way to explain it is by examining the two functions in Listing 4-2. The first function, Jeckle, defines a variable named monster. The second function, Frankenstein, also defines a variable named monster. Because both variables are local, Jeckle's monster is a different monster than Frankenstein's.
Listing 4-2. Two Local Variables
Global scope refers to variables that are defined throughout the entire page. They are defined in one of two ways, either using a var and declaring the variable outside a function, or omitting the var and declaring it within a function. I don't have a problem with the first method of declaring a global variable, but I have some definite issues with the second. All that it takes is one case of "sausage fingers"; a mistyped variable name, and I'm debugging for hours.