JS Scope chain

Source: Internet
Author: User

JS scope and execution Environment:

1. Scope Chain:

<1> use: Ensures an orderly access to all variables and functions that the execution environment has access to.

<2> Composition:

A. The front end of a scope chain is always a variable object in the context of the current execution code (if the environment is a function, its active object is used as a variable object, and the active object initially contains only one variable, the arguments object);

B. The next variable object comes from the containing (external) environment;

C The last object, the variable object for the global execution environment.

<3> identifier parsing: is the process of searching for identifiers one level along the scope chain, always starting at the front end of the scope chain, and then backtracking backwards until the identifier is found.

2. Extend the scope chain:

Catch block for <1>try-catch statement: Creates a new variable object that contains the declaration of the thrown Error object;

<2>with statement: The specified object is added to the scope chain;

3. There is no block-level scope in JS:

<1> the variable declaration in the IF statement adds the variable to the current execution environment;

<2> variables declared with Var are automatically added to the closest environment

JS Scope chain

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.