current position:Home>Front end interview series 5: browser and computer foundation

Front end interview series 5: browser and computer foundation

2021-08-27 00:34:26 Rookies of Xiaoheshan

Come and join us !

" Rookies of Xiaoheshan ", Provide technical information and series of basic articles for front-end developers . For better user experience , Please move to our official website, Rookies of Xiaoheshan ( ) To study , Keep abreast of the latest articles .

"Code tailor" , If you are interested in our article 、 Or I want to make some suggestions , Wechat attention “ Rookies of Xiaoheshan ” official account , Get in touch with us , You can also watch our articles on wechat . Every suggestion or approval is a great encouragement to us !

The interview series is updated from time to time , Stay tuned


This column focuses on the interview browser / Basic computer knowledge The content of the interview questions .

Be careful : This column will only cover the key content , It will not expand . Some topics need to expand knowledge points , We will expand the content 、 The overall details are placed at the top of each topic , You can check it by yourself .

browser / Basic computer knowledge

browser / Basic computer knowledge
Difference between process and thread
Why? JS To set as single threaded
Browser event loop
When to trigger the browser's event loop
Script Of async and defer The difference between loading


Difference between process and thread

  • A process is a running program , A thread is an execution sequence inside a process
  • A process is a unit of resource allocation , Threads are execution units
  • High cost of inter process switching , The cost of switching between threads is small
  • Processes have many resources , Threads have less resources
  • Multiple threads share the resources of the process

Why? JS To set as single threaded

JavaScript The reason for being single threaded is related to its purpose ,JavaScript Its main purpose is to interact with users , And operation DOM. This determines that it can only be a single thread , Otherwise, it will bring complicated synchronization problems . such as , Assume JavaScript There are two threads at the same time , A thread in a DOM Add content on node , Another thread deleted this node , Which thread should the browser follow ?

therefore , To avoid complexity , From the birth ,JavaScript It's a single thread , This has become the core feature of the language , It won't change in the future .

Browser event loop

The browser event loop refers to JS The engine is parsing JS Script time , Push the synchronization method into the execution stack , And put asynchronous methods in 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 is , Then take it out and put it into the execution stack . Repeating the above actions repeatedly is called an event loop

The answer needs to be connected with the browser thread , namely JS Engine threads 、 Event trigger thread 、 Timing trigger thread

For more details, see JavaScript Detailed explanation of operation mechanism : We can talk Event Loop

Script Of async and defer The difference between loading

For more details, see defer and async The difference between

Notice of next section

In the next section, we will bring you Handwritten program algorithm problem My interview questions , Coming soon !

copyright notice
author[Rookies of Xiaoheshan],Please bring the original link to reprint, thank you.

Random recommended