The JavaScript start to make sense with the help of Namaste JS.
JavaScript is single-threaded. It can only do one thing at a time. So how does it handle timers, API calls, and other async stuff without freezing?
Turns out, it doesn't. The browser does.
JavaScript hands off async operations to the browser (Web APIs), keeps running your code, and picks up the results later when it's free. The event loop is just the thing that coordinates all of this.
The tricky part? Understanding why this prints in this order:
setTimeout → goes to callback queue
Promise → goes to microtask queue (higher priority)
Promises always cut the line. That's why they execute before setTimeout, even with 0ms delay.
Documented the whole flow with examples: https://lnkd.in/dC3mh_AV
If the event loop still feels like magic, maybe this helps.
#JavaScript #WebDev #Coding #LearningInPublic
It seems fine for production. I just have to ask myself, when would I want a new kind of iterable object rather than just a generator function? The advantage of a Range object over `function* range(from, to)` is that I can retrieve `range.from` and `range.to` later, I suppose. I can't see it being the clearest way often, but maybe sometimes!