In this paper, we analyze the difference between the Var and the variable with the JavaScript definition variables. Share to everyone for your reference. The specific analysis is as follows:
Look directly at the example to illustrate:
Copy Code code as follows:
<script language= "javascript" type= "Text/javascript" >
var abc=89;//with Var, representing global variables
function Test () {
var abc=80;//within a function, if not Var, means using a global variable outside the function; Var, which represents a new definition of a global variable
}
Test ();
Window.alert (ABC);
</script>
Strictly speaking: The function body does not take the Var, does not mean defines a variable, but carries on the variable assignment value, namely Var abc;abc=8. If you are assigning abc=80 (without Var) in the body of the function, the real process is this--the statement first finds the variable ABC in the body of the function, and if it doesn't, it goes up to look for the variable ABC outside the function body, and if it's still not there, there's no way to define the variable var ABC in the function body.
So, why
Copy Code code as follows:
function Test () {
ABC = 80;
}
The ability to call variable ABC directly outside of a function is one such reason.
I hope this article will help you with your JavaScript programming.