these two things disturb and irritate a lot when learning JS.
Really? I'd flip it around and claim that until you understand JavaScript's event loop, task and microtask queues you're going to have a hard time understanding its bread-and-butter asynchronous behaviour given that it has to accomplish work concurrently on a single thread.
setTimeout and setInterval run on the Task queue, Promises (and therefore async/await) run on the microtask queue.
Really? I'd flip it around and claim that until you understand JavaScript's event loop, task and microtask queues you're going to have a hard time understanding its bread-and-butter asynchronous behaviour given that it has to accomplish work concurrently on a single thread.
setTimeout
andsetInterval
run on the Task queue, Promises (and therefore async/await) run on the microtask queue.Resources:
Helpful man. Thanks.