当前位置:网站首页>Scope and scope chain

Scope and scope chain

2022-06-12 20:35:00 Stand on the bridge and bake cold noodles

1. Scope

a. What is? : Save the available range of a variable

b.js Contains two levels of scope : Global scope and function scope

2. The principle of scope

When defining a function , Each function will store global variables and variables created by itself in the function body ,

When you call a function , Create scope objects temporarily , And save the scope object , Every variable used , The function first looks for itself , If you can't find it, you will go to the global search , Follow the principle of proximity . When the function call is complete , You will know the variables created inside the function body , Therefore, local variables cannot be used after the function call is completed .

3. Scope chain

What is? ? It stores the chain structure of all available scope objects of a function

 

原网站

版权声明
本文为[Stand on the bridge and bake cold noodles]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206122029151976.html