Home > Article > Web Front-end > Is javascript single process or multi-threaded?
Javascript is a single process. As a browser scripting language, the main purpose of JavaScript is to interact with users and operate the DOM, which determines that it can only be single-threaded, otherwise it will cause many complex synchronization problems.
#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
JavaScript is single-threaded, which is a major feature of it. That is, JavaScript can only do one thing at a time.
As a browser scripting language, the main purpose of JavaScript is to interact with users and operate the DOM, which determines that it can only be single-threaded, otherwise it will cause very complex synchronization problems. For example, suppose JavaScript has two threads at the same time. One thread adds content to a certain DOM node, and the other thread deletes the node. In this case, which thread should the browser use?
In order to take advantage of the computing power of multi-core CPUs, HTML5 proposes the Web Worker standard, which allows JavaScript scripts to create multiple threads, but the child threads are completely controlled by the main thread and must not operate the DOM. Therefore, this new standard does not change the single-threaded nature of JavaScript.
Recommended learning: javascript video tutorial
The above is the detailed content of Is javascript single process or multi-threaded?. For more information, please follow other related articles on the PHP Chinese website!