Let’s start with a metaphor

A process is a company, and each company has its own resources to schedule; Companies are independent of each other; A thread is each employee (you, me, him) in a company. Multiple employees work together to complete a task. The company can have one or more employees sharing the company space

What is a process?

Process: is the smallest unit of resources allocated by the CPU; (The smallest unit that can have resources and operate independently)

What is a thread?

Thread: is the smallest unit of CPU scheduling; (A thread is a unit of running a program at a time based on a process. There can be multiple threads in a process.)

Browsers are multi-process

In the browser, every time a TAB page is opened, a new process is actually opened. In this process, there are UI rendering threads, JS engine threads, HTTP request threads, etc. So, the browser is multi-process.

Everyone says JS is single threaded, but why single threaded?

This is mainly related to the use of JS, JS as a browser scripting language, mainly to achieve user interaction with the browser, as well as dom operation; This means that it has to be single-threaded, which can cause complex synchronization problems. For example, if js is designed to be multithreaded, the browser will look confused if one thread tries to modify a DOM element and another thread tries to delete it. So, to avoid complexity, JavaScript has been single-threaded since its inception, and this has been a core feature of the language and will not change

In order to make use of the computing power of multi-core CPU, 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 cannot operate DOM. So, this new standard doesn’t change the single-threaded nature of JavaScript.