join us!
Mountain" , to provide front-end developers with technical information and a series of basic articles. For a better user experience, please move to our official website novices (16128634b46531 https://xhs-rookies.com/ ) to learn and get the latest articles in time.
"Code tailor" , if you are interested in our article or want to make some suggestions, follow Mountain" public account, contact us, you can also watch it on WeChat Our article. Every suggestion or approval is a great encouragement to us!
Interview series are updated from time to time, please stay tuned
Preface
This column focuses on explaining the browser/computer basic knowledge interview questions in the interview.
Note: This column will only involve key content and will not be expanded. For some topics that need to expand knowledge points, we will place the expanded content and overall detailed information at the top of each topic, and you can check it by yourself.
Basic knowledge of browser/computer
Basic knowledge of browser/computer |
---|
The difference between process and thread |
Why JS should be set to single thread |
Browser event loop |
When to trigger the browser's event loop |
The difference between async and defer loading of Script |
Problem analysis
The difference between process and thread
- A process is a running program, and a thread is an execution sequence inside the process
- Process is the unit of resource allocation, thread is the unit of execution
- The cost of switching between processes is high, and the cost of switching between threads is small
- Process has more resources, thread has fewer resources
- Multiple threads share the resources of the process
Why JS should be set to single thread
JavaScript
reason why 06128634b46884 is single-threaded is related to its purpose. JavaScript
is to interact with users and operate DOM
. This determines that it can only be single-threaded, otherwise it will bring very complicated synchronization problems. For example, suppose JavaScript
has two threads at the same time. One thread DOM
node, and the other thread deletes this node. At this time, which thread should the browser use?
Therefore, in order to avoid complexity, JavaScript
has been single-threaded since its birth. This has become the core feature of the language and will not change in the future.
Browser event loop
The browser event loop means that when the JS
engine parses the JS
script, it pushes the synchronous method onto the execution stack and puts the asynchronous method into the event queue. When the method in the execution stack is executed, the browser goes to the event queue to see if There are completed tasks, if there are, they are taken out and placed on the execution stack. Repeating the above actions repeatedly is called an event loop
The answer needs to be linked to the browser thread, that is, JS
engine thread, event trigger thread, and timing trigger thread
For more details, please refer to JavaScript operating mechanism detailed explanation:
The difference between async and defer loading of Script
For more details, see The difference between defer and async
Preview of the next section
In the next section, we will bring you the questions of 16128634b469fe handwritten program algorithm questions, so stay tuned!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。