JS Scope, scope chain

Source: Internet
Author: User

1 Scope ( global scope)objects that can be accessed anywhere in your code have global scope, and in general there are several scenarios where you have global scope:(1) The outermost function and the variables defined outside the outermost function have global scope. (2) All variables that do not have a direct assignment defined are automatically declared as having global scope. (3) All Window object properties have global scope 2 scope ( local scope)In contrast to global scopes, local scopes are generally accessible only within a fixed code fragment, the most common of which is inside a function, and in some places it is also seen that this scope is called a function scope.  3. Scope chain (scope Chain)when a function is created, it fills a global object in its scope chain, which contains all global variables.

JS Scope, 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.