[13] JS Tutorial Variable Scope

It refers to the variable scope scope variables, javascript variables into global variables and local variables .

1, global variables: variables defined outside the function, the entire page is public, internal and external functions are accessible.
2, local variables: the function of the internal variables defined only in the definition of the internal function of the variable access, external inaccessible.

<Script type = "text / JavaScript">
     // define global variables 
    var A = 12 is ;
     function myalert () 
    { 
        // definition of local variables 
        var B = 23 is ; 
        Alert (A); 
        // modify global variables 
        A ++ ; 
        Alert (B ); 
    } 
    myalert (); // pop 12 and 23 is 
    Alert (A);   // pop-up 13 is     
    Alert (B);   // error 
</ script>

 

Guess you like

Origin www.cnblogs.com/zeug/p/11387254.html