JS Variable pre-compilation

Source: Internet
Author: User

JS is executed in sequence;

However, in JS, Var and function are precompiled;

        alert (show);         function Show () {            var  A;        }

For example the above code, alert will output function.

But for the pre-compilation of Var, it was just the wrong idea.

The following code, the a output is undefined.

B will directly error, B is not defined.

   alert (a);   alert (b);    var A;

Summary of the following points:

1.js is executed sequentially during the page load process. But chunking is precompiled and executed.
2.JS performs a similar "precompiled" operation before execution, and pre-declares the variable to predefine the function.
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.
3. (note) It is not a full-text compilation in the execution, but a block compilation, that is, a script block, precompiled and then execute, and then (in order) the next script block, precompiled and then execute, but at this time the data in a block can be used, but the next block of functions, declared variables are not available.
4. The variable does not declare the reference, will error, but the object method, object variable is not declared, is undefined
5. In the function, the variable is not declared in the assignment, it will be considered as a global variable, declared with Var as the function variable
6. 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) does not have an effect if the function is not executed, but an execution function that begins the function precompilation error.

JS Variable pre-compilation

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.