Remarkable efforts and unbelievably effective and concise. Keep making these behind the scences in depth videos very few people cover these and less than a handful can deliver it effectively.
There is a single Message Queue (Task Queue) in JavaScript for handling asynchronous operations. This queue includes tasks related to DOM events (e.g., click events) and network requests (e.g., HTTP requests). Within the Message Queue, there are two different types of tasks: the Callback Queue (for functions like setTimeout callbacks) and the Microtask Queue (for high-priority tasks like promises and certain DOM-related tasks). The Microtask Queue has a higher priority than the Callback Queue, and the event loop first serves the Microtask Queue before moving to the Callback Queue. This ensures that tasks in the Microtask Queue are executed immediately and in order, while tasks in the Callback Queue are processed when the call stack is empty. Promises and network requests typically go to the Microtask Queue due to their high-priority nature.
Remarkable efforts and unbelievably effective and concise. Keep making these behind the scences in depth videos very few people cover these and less than a handful can deliver it effectively.
Thanks a lot for the kind words :)
Great explanation!
And about the question, I think the setTimeout with 0 sec would still wait in the queue till the other functions get executed.
true
Perhaps setTimeout with 0 passed is a way to do non blocking code. Like async or something.
does every function has it's own personal message queue? what if there's async code within async code? will it go to queue or stack?
There is a single Message Queue (Task Queue) in JavaScript for handling asynchronous operations. This queue includes tasks related to DOM events (e.g., click events) and network requests (e.g., HTTP requests). Within the Message Queue, there are two different types of tasks: the Callback Queue (for functions like setTimeout callbacks) and the Microtask Queue (for high-priority tasks like promises and certain DOM-related tasks). The Microtask Queue has a higher priority than the Callback Queue, and the event loop first serves the Microtask Queue before moving to the Callback Queue. This ensures that tasks in the Microtask Queue are executed immediately and in order, while tasks in the Callback Queue are processed when the call stack is empty. Promises and network requests typically go to the Microtask Queue due to their high-priority nature.
to avoid that ,async concept we need to use