JS: Scope Summary

What is the scope? You can access a set of variables, objects, functions.

Avatar: into the global scope with the function scope

1576829785(1)

1, all of the global scope are interoperable

2, variable declaration var attributes will be mounted inside the window, and let, const does not

3, has its own independent scope function, can not be accessed outside, the outer function nested inner function, the scope is inclusion relation

Scoping rules:

1, search rules: Functions (local)> parent function (closed)> Global layers from inside to outside to read

2, scope, just look at environmental declaration, do not watch the execution environment

var scope block scope and let the difference between:

image

As can be seen:

1, in accordance with the variable var statement for executing the loop, when i = 10> for the number of cycles performed in a timer, sequentially printing the value at that time i

2, let the variable declaration is in accordance with the implementation of a for loop, execute the timer immediately, in order to print out 0-9

3, for the outer loop, you can print out the value of i in this case 10

4, for the outer loop, is being given the value of the print j

the reason:

   let each time assignment, creating a block scope, and is unable to access external block variable under the scope, the scope of the rules is accessible from the inside out

Closure See: https://www.cnblogs.com/hxw1024/p/12070523.html

Guess you like

Origin www.cnblogs.com/hxw1024/p/12074362.html