Although modern browsers can download JavaScript in parallel (some browsers), considering the dependencies of JavaScript, their execution is still carried out in the order of introduction.
This article records some of the things I learned from reading books while learning JavaScript, to deepen my memory and organize and record them for later review.
Execution order in html document
The image of js code execution order comparison, users can intuitively feel this execution order. However, the execution order of js code is more complicated. Sometimes we write js code in html, and the process of parsing the html document in the browser is as follows: the browser gradually parses the page structure and information from top to bottom according to the document flow. As an embedded script, js code is also considered a component of the html document. Therefore, the execution order of the js code during loading is also determined based on the order in which the script tag