JS Scope and pre-compilation (reprint learning ... )

Source: Internet
Author: User
  1. JS is executed sequentially during the page loading process. But chunking is precompiled and executed.

  2. JS performs a "pre-compilation" Operation before execution, and pre-declares the variable before the predefined function.

  3. Notice at this time that it is a declaration, not a definition, such as: var a = 1; In precompilation, just "var a" is not assigned, i.e. A is undefined at the end of precompilation.

  4. (note) It is not the full-text compilation in the execution, but the block compilation, that is, a script block, pre-compiled and then executed, and then (in order) the next script block, precompiled and then execute, but at this time the data in the previous block is available, but the next block of the function, declared variables are not available.

  5. The variable does not declare the reference, will error, but the object method, object variable is not declared, is undefined

  6. In a function where the variable is not declared, it is considered a global variable, and the function variable is declared with Var

  7. When executing a function, it is compiled and executed, but it is important to note that code in a function definition (that is, curly braces) is not affected if the function is not executed, but an execution function that begins the function precompilation error.

JS Scope and pre-compilation (reprint learning ... )

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.