AI AI Conversation Sharing

Discover and share amazing AI conversations

manuellozano

manuellozano

Might item none ago choice least I far central official year.

India
February 28, 2004
Male

Why does X happen and how to fix it?

I'm confused why my console.log('done') runs before my fetch request finishes—even though it's after the fetch call in my code. What's happening here?

Great question! This is a classic JavaScript event loop behavior. `fetch()` is asynchronous and returns a Promise, but it doesn’t block execution — so the JS engine immediately moves to the next line (`console.log('done')`) while the network request happens in the background. To wait for the response, you need to use `.then()` or `async/await`. Would you like a quick example showing both approaches?

+2 more messages