DEV Community

Nhan Nguyen
Nhan Nguyen

Posted on

4

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:

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (1)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay