Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the scope and scope chain of Javascript

Shulou Source: shulou.com Published: 2022-06-01 03:46:06 10月02日 Update

This article mainly introduces what is the scope and scope chain of Javascript. It is very detailed and has certain reference value. Friends who are interested must finish it.

Scope and scope chain of Javascript

Scope: a scope is the area that defines variables and has a set of rules for accessing variables that govern how the browser engine looks up variables (identifiers) based on variables in the current scope as well as in nested scopes.

Scope chain: the function of the scope chain is to ensure orderly access to all variables and functions that the execution environment has access to. Through the scope chain, we can access the variables and functions of the outer environment.

The scope chain is essentially a list of pointers to variable objects. A variable object is an object that contains all variables and functions in the execution environment. The front end of the scope chain is always the variable object of the current execution context. The variable object of the global execution context (that is, the global object) is always the last object in the scope chain.

When we look for a variable, if it is not found in the current execution environment, we can look back along the scope chain.

The process of creating a scope chain is related to the establishment of the execution context.

The above is all the content of the article "what is the scope and scope chain of Javascript". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Function variable object environment up and down context function global content article rule order that is value interest area outer layer boy partner engine Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux Apple Shulou Tech Info MySQL