The lexical scope of JS

Source: Internet
Author: User

Lexical scopes define the rules for implementation:

1 function scope is defined at the time of definition, not at the time of execution

2 to implement this lexical scope, the function contains not only the function code logic but also the current scope chain.

3 function objects can be interconnected by a scope chain, and variables inside the function can be stored within the scope of the function.

Variable scope: The scope of a variable is the area in the program source code that defines the variable.

1 inside a function, local variables take precedence over global variables with the same name.

2 JS is a function scope

3 function Scope: A variable is defined within the body of the function in which it is declared and within a function nested inside the function.

The function scope of 4 JS refers to: All variables declared within a function are always visible inside the function body.

5 variables as attributes: Variables declared with VAR are not configurable

6 Local variables can be considered as properties of a local object

7 If you consider a local variable as a property of a local custom object, then each piece of JavaScript code has a scope chain associated with it. And the scope chain is made up of some columns of objects, and this scope chain defines the scope of the variable.

8 When a function is defined, it actually saves a scope connection, and when called, it creates a new object to store her local variables, and adds the object to the saved scope face, creating a new scope "chain" that represents the function call.

The 9 object does not have a closure feature.

The lexical scope of JS

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.