JavaScript ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ฎ๐๐ธ ๐ค๐๐ฒ๐๐ฒ and ๐ ๐ฎ๐ฐ๐ฟ๐ผ๐๐ฎ๐๐ธ ๐ค๐๐ฒ๐๐ฒ
JavaScript has two secret queues to handle tasks: ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ฎ๐๐ธ ๐ค๐๐ฒ๐๐ฒ and ๐ ๐ฎ๐ฐ๐ฟ๐ผ๐๐ฎ๐๐ธ ๐ค๐๐ฒ๐๐ฒ.
โจ๐ ๐ถ๐ฐ๐ฟ๐ผ๐๐ฎ๐๐ธ ๐ค๐๐ฒ๐๐ฒ: 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:
Hashnode: https://nhannguyen.hashnode.dev/
X (formerly Twitter): https://twitter.com/nhannguyendevjs/
Buy Me a Coffee: https://www.buymeacoffee.com/nhannguyendevjs