1. For outer variables, the inner layer can find the (global) inner layer variables, and the outer layer cannot find (local) 2. When VaR is not added, the global variables will be automatically generated (it is not recommended to write this way, it is best to add all the variables to be defined with VAR) 3. The search for variables is based on the proximity principle. The variables defined by VAR are, when the nearest area is not found, the outer layer is located, and the outer layer is located one by one. 4. When the parameter and the local variable have the same name, the priority is the same. 5. The value assignment of the basic type is only worth the value assignment, rather than the reference relationship, and there is a reference relationship between objects (the addresses inside are the same). Basic Type: var A = 5; vaR B =;
B + = 3;
Alert (B); // 8
Alert (a); // 5 object type: var A = [1, 2, 3];
VaR B =;
B. Push (4 );
Alert (a); // [1, 2, 3, 4]
Alert (B); // [1, 2, 3, 4] var A = [1, 2, 3]; var B =;
B = [1, 2, 3, 4]; // It is not a public address, but a newly created
B. Push (4 );
Alert (a); // [1, 2, 3]
Alert (B); // [1, 2, 3, 4]
Variables and scopes