1. The following outputs are:
Undefined
Local variables
<script type= "Application/javascript" >
var scope= "global variable";
Function cal () {
Document.writeln (scope+ "<br/>");
var scope= "local variables"; (1) Office
Document.writeln (scope+ "<br/>");
}
Cal ();
</script>
2. If the above is not understood, it is easy to understand that the scope of the function is changed to Scope1.
Cause: The variable in the function is a local variable, and the entire scope is within the function. Here is the main definition of variables with Var and not the difference between var.
That is: 1) If you use Var, the program will force a new variable to be defined
2) If not used, the system takes precedence over whether the variable exists in the current context (not just above, but also below) . The system is redefined only if the variable does not exist.
Therefore, the scope defined below is found in 1, but is not assigned at (1), so the undefined is displayed.
The easy mixing point of local variables and global variables in JS