JavaScript execution sequence _ javascript skills

Source: Internet
Author: User
JavaScript is a descriptive scripting language. It is different from compiling languages such as java or C #. It does not need to be compiled into an intermediate language, but is dynamically parsed and executed by the browser. If you cannot understand the running mechanism of the javaScript language, or simply put, you cannot master the execution sequence of javascript, then you are like bole cannot control qianma. Although modern browsers can download JavaScript in parallel (Some browsers), their execution is still carried out in the order of introduction considering the JavaScript dependency.

This article records some of the things I have learned in JavaScript, deepen my memory and record it, so that I can easily review it later.

Execution sequence in html document

By comparing the execution sequence of js code, you can intuitively feel the execution sequence. However, the execution sequence of js Code is complicated. Sometimes we write JavaScript code in html, and the html document parsing process in the browser is like this: the browser parses the Page Structure and information from top to bottom according to the document stream. Js Code, as an embedded script, is also part of the html document. Therefore, the execution sequence of js Code during loading is determined by the sequence in which the script tag script appears. (The following is a chestnut)

Script console. log ("top script"); script  
   DocumentScript console. log ("header script"); scriptScript console. log ("page script"); scriptScript console. log ("bottom script"); script

For external js file scripts imported using the src attribute of script, it will also be executed according to the order in which the statements appear, and the execution process is part of the document loading, the execution will not be extended because it is an external js file.

// Load B. js first and execute the code in it

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.