3 ms·
> Thinking about the event loop opens up a can of worms I find more confusing than useful. Probably for daily usage this might be true, but there are definitel
by capableweb 3y ago
> Thinking about the event loop opens up a can of worms I find more confusing than useful.
Probably for daily usage this might be true, but there are definitely cases when you're using JavaScript and not understanding the event loop makes it hard to understand why things are happening. Example:
setTimeout(() => console.log('hello'), 0)
console.log('world')
You'd normally expect this to print "hello" and then "world" since the "sleep time" for the setTimeout is set to 0, but thanks to the event loop, the result will be "world" and "hello". Very simple example, but in real life code bases and beginner JavaScript developers, in can be confusing at times.