98
I'm trying to understand the JavaScript event loop. I know JavaScript is single-threaded, but how does async code work then?
Can someone explain:
- What is the call stack?
- What is the task queue?
- What is the microtask queue?
- How do they all work together?
This code confuses me:
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');Why does it print 1, 4, 3, 2?