I believe you are not unfamiliar with global variables, in the function scope of the a=1 this form of the variable is defined as a global variable, in the global scope, in the following 3 forms can be created on the global visible name:
Copy Code code as follows:
<script>
var a = 1;
b = 2;
WINDOW.C = 3;
</script>
For b=2 this way, it is actually the same as C, when executing this assignment statement, it follows the scope chain to find the variable named B, and finds that the top of the scope chain has not been found yet, and then adds a property B to the window and assigns the value.
There are two differences between Var and no Var:
The global variable of 1 var cannot be deleted because the Delete smart Delete object's removable properties, and the global properties defined by VAR are marked as not to be deleted. It should be explained that delete is unsuccessful and will not be thrown incorrectly, and the return value of delete is True|false.
2 The global variables defined by VAR are promoted, and global variables defined without VAR are not promoted. You can see the results of the following program:
Copy Code code as follows:
<script>
alert (a);
var a=1;
</script>
Copy Code code as follows:
<script>
alert (a);//error, a undefined
A=1;
</script>