On macro task and micro task;

Definition: tasks initiated by the host (browser) can be called macrotasks; The engine (JS) itself can also initiate a task, which is called a microtask.

Js is basically a single-threaded language, and the first thing to do is to execute a synchronous queue, which you can only put aside for asynchronous operations. Synchronization won’t be discussed too much.

So those that initiate are macro and those that initiate are micro;

Macro task

Script, setTimeout, setInterval, I/O, UI interaction events, postMessage, MessageChannel, setImmediate(node.js environment);

The micro tasks

promise async await  

Therefore, the overall execution sequence is:

Synchronous Task > Micro Task > Macro Task

Take the following example

The first is the synchronization queue log(4) ==>async1==> Async2 ==> Promise ==>log8

Micro task log(2)==>log(7)

Macro task setTimeout

So the output result 41368275==

Ali rookie interview yesterday, received rejection mail today, before still can insist on two or three rounds, hit. That’s probably the problem. I feel like I didn’t answer that well. Better late than never. Hope the latecomers meet play well.

What happens when you manipulate a primitive array in a WEBGL JS loop? React ShoudComponentUpdate React ShoudComponentUpdate Stop rendering vue why don’t you use 11 methods for deep copy shallow copy Vue vue $nextTick Deep parsing Deep Revealing Promise microtask registration and execution Process How does the V8 engine execute a section of JS code? Http3.0 2.0 1.0 compare macro tasks and micro tasks in detail