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:
- Medium: https://medium.com/@nhannguyendevjs/
- Dev: https://dev.to/nhannguyendevjs/
- Hashnode: https://nhannguyen.hashnode.dev/
- Linkedin: https://www.linkedin.com/in/nhannguyendevjs/
- X (formerly Twitter): https://twitter.com/nhannguyendevjs/
- Buy Me a Coffee: https://www.buymeacoffee.com/nhannguyendevjs
Top comments (1)