- JavaScript is single-threaded.
- The event loop handles asynchronous tasks (like promises, timers) by moving them from the callback queue to the main execution stack when it’s free.
Example:
console.log("Start");
setTimeout(() => console.log("Callback"), 0);
console.log("End");
// Output: Start → End → Callback
Even with 0ms
, the async callback runs after synchronous code.
Leave a Reply