One, the external is global, internal is local variable.
Second, add var as local variable (within the method), without VAR as global variable (once used in the method)
Copy Code code as follows:
<script type= "Text/javascript" >
var golbe= "global";
Test ();
function Test () {
var local= "local";
document.write (Golbe);
document.write (local);
}
document.write (Golbe);
document.write (local);
</script>
In the test method above, when the Var of the local variable is removed, the locality becomes a global variable, but it is not used locally as a whole, which is not valid for the global.
To verify this, I comment out the only code inside the test method that uses the local variable. The discovery is not printed outside.
Summary: Global variables can declare var without declaring Var, while defining global variables with or without the VAR keyword has little effect, but if the local variable is defined without the var keyword javascript interpreter interprets it as a global variable.