🟢 EasyAsync JS📖 Theory Question

How does async/await work under the hood?

💡

Hint

Syntactic sugar over Promises; await pauses the function, not the thread

Full Answer

async/await is syntactic sugar over Promises. An async function always returns a Promise. await pauses only that function's execution.

async function fetchUser(id) {
  try {
    const res = await fetch(`/api/users/${id}`);
    if (!res.ok) throw new Error('Not found');
    return await res.json();
  } catch (err) {
    console.error(err);
  }
}
💡 Parallel fetching: use Promise.all([fetch(a), fetch(b)]) instead of sequential awaits — ~2x faster.

More Async JS Questions

🟢 EasyExplain Promises — states, chaining, and error handling.→🟢 EasyWhat is callback hell and how do you avoid it?→🟢 EasyWhat are Promise combinators and when do you use each?→🟢 EasyWhat is queueMicrotask() and when should you use it?→

Practice this in a timed sprint →

5 free questions, no signup required

âš¡ Start Sprint