12.7 Parallelizing Tasks
JavaScript is a language that is executed as single-threaded, meaning that multiple scripts cannot be executed at the same time (see Figure 12.20). Scripts are interpreted and executed one after the other, line by line.
Also, the triggering of events and the associated execution of event listeners do not happen in parallel: the code that triggers an event pauses until the corresponding event listeners have been executed.
The same applies to callback functions. For example, if you make an Ajax request to a server, the script that makes the request continues to execute until the server prepares the response and sends it to the client, but as soon as the callback function that evaluates the response from the server is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access