Note: Elevation of variable declarations

Source: Internet
Author: User

Any variable declared within a scope will be attached to that scope.

We habitually put var a = 2; as a life, and in fact the JavaScript engine does not think so. It treats var A and a = 2 as two separate declarations, the first is the task of the compilation phase, and the second is the task of the execution phase.

This means that regardless of where the declaration in the scope appears, the process can be visually imagined as all declarations (variables and functions) will be "moved" to the top of their respective work before the code itself is executed, a process known as Ascension. The declaration itself is promoted, and the assignment operation, including the assignment of a function expression, is not promoted.

Note: Elevation of variable declarations

Related Article

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.