In JavaScript, how does async/await work, and how does it relate to Promises and callbacks?

technical-conceptual · Junior level · software-engineering

What the interviewer is really asking

Probes whether the candidate understands that async/await is built on Promises and writes readable asynchronous code rather than nesting callbacks.

What to say

What to avoid

Example answers

Strong: async/await is sugar over Promises: an async function returns a Promise, and await pauses just that function until the Promise resolves while the event loop keeps handling other work, so nothing freezes. It came out of callbacks, which nested into callback hell, then Promises that you chained with .then; async/await lets the same logic read top-to-bottom. I use try/catch to handle rejected Promises, and Promise.all when several calls are independent so they run in parallel instead of one at a time.

Weak: async and await make your code wait for something to finish before moving on, so it pauses the whole program until the data comes back. It's a totally new thing that replaced Promises, you don't really need Promises anymore once you have async/await. I just put await in front of anything that's slow and it handles it.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.