DEV Community

Nhan Nguyen
Nhan Nguyen

Posted on

JavaScript š— š—¶š—°š—暝—¼š˜š—®š˜€š—ø š—¤š˜‚š—²š˜‚š—² and š— š—®š—°š—暝—¼š˜š—®š˜€š—ø š—¤š˜‚š—²š˜‚š—²

JavaScript has two secret queues to handle tasks: š— š—¶š—°š—暝—¼š˜š—®š˜€š—ø š—¤š˜‚š—²š˜‚š—² and š— š—®š—°š—暝—¼š˜š—®š˜€š—ø š—¤š˜‚š—²š˜‚š—².

Image description

āœØš— š—¶š—°š—暝—¼š˜š—®š˜€š—ø š—¤š˜‚š—²š˜‚š—²: It's like a super-fast line where tiny tasks wait their turn. These tasks are usually promises or mutation observers. When a promise resolves or a mutation happens, they jump into the Microtask queue.

āœØ š— š—®š—°š—暝—¼š˜š—®š˜€š—ø š—¤š˜‚š—²š˜‚š—²: It's like a regular line for more significant tasks. Think setTimeout, callbacks, or fetching data from a server. When these tasks need handling, they join the Macrotask Queue.

JavaScript always finishes what it's doing before checking these queues. But it prioritizes š— š—¶š—°š—暝—¼š˜š—®š˜€š—ø over š— š—®š—°š—暝—¼š˜š—®š˜€š—ø.


I hope you found it helpful. Thanks for reading. šŸ™

Let's get connected! You can find me on:

Top comments (1)

Collapse
 
raajaryan profile image
Deepak Kumar

Hello everyone,

I hope you're all doing well. I recently launched an open-source project called the Ultimate JavaScript Project, and I'd love your support. Please check it out and give it a star on GitHub: Ultimate JavaScript Project. Your support would mean a lot to me and greatly help in the project's growth.

Thank you!