Analysis of JS execution sequence

Source: Internet
Author: User

JavaScript is a descriptive script language, is a parsing language, by the browser dynamic parsing, different types of browsers different versions of the browser for the analysis of JS has a small difference, different browsers of the JS parsing engine efficiency is high and low, the following to analyze the sequence of JS execution, I hope that we can help, and welcome everyone to communicate correct.

First of all, JS execution process is divided into two parts, the first part, the parsing process, also known as the pre-compilation period. The main task is to pre-process all the variables and functions declared in the JS code. It is important to note that this is only the declaration function, and the processing of the variable is only a declaration, and a piece of memory space, no copy operation.

The second part, the execution process, in the execution process, the browser's JS engine for each block of code execution, if there is an external reference to JS, and JS is interrelated, it is important to note that the introduction of different JS sequence, if the declaration code block after calling the code block will not achieve the desired effect.

In summary, the execution of JS is divided into two parts, the parsing process and the execution process. Parsing, in accordance with the code block, a period of parsing, execution in accordance with the code block sequential execution, parsing a block of code, execute a block of code. Because it is an explanatory language, so JS if there is error in the parsing process, you will not be prompted, you can also understand that JS does not compile errors, but if a run-time error occurs, all the JS code error will not continue to execute.

Here's a piece of code that gives you an example of how the process is performed.

Phenomenon 1. By the first part of the JS call the second part of a function, the result is not output, indicating that JS in the event of a run error, the rest of the code will not be executed.

Phenomenon 2. The second code function call before the definition, but output the "second paragraph JS", the results show that in the pre-compilation period, the engine for the JS defined function declaration, and open up the memory space.

Phenomenon 3. The third paragraph js,alert (WORD2) output undefined, the results show that JS in the pre-compilation period, only the variables, declaration, open up memory space, not assigned.

The 4.b function does not make a smooth call, because JS does not assign a value to the reason that the B function is declared.

Phenomenon 5.button can prompt go, and can not prompt the come, the results show that in the event of a run error after the block JS code is not executed.

  

Analysis of JS execution sequence

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.