JavaScriptPromises And Asyncintermediate

JavaScript Promises and Async/Await Interview Questions

Asynchronous JavaScript is the most-tested topic in front-end interviews — the event loop, callbacks, promises, async/await, error handling and the Promise combinators, answered with code.

Published
TL;DR – Quick Answer

Async JavaScript interviews start with the event loop — synchronous code first, then microtasks such as promise callbacks, then macrotasks such as setTimeout — and continue with callbacks, promises, async/await, error handling and the combinators Promise.all, allSettled, race and any. Expect at least one output-ordering question and one task that runs requests in parallel.

On This Page

Almost every real JavaScript program waits for something — a network call, a timer, a user click — so asynchronous code is the most-tested area in front-end interviews. This guide covers the event loop, callbacks, promises, async/await, error handling and the four promise combinators.

Why interviewers ask about JavaScript promises and async/await

Async bugs are the hardest to spot in code review: requests that run one after another when they could run in parallel, errors that vanish, state that updates in the wrong order. Interviewers ask these questions because they predict whether you will write those bugs.

The event-loop output question in particular is a favourite. It is short, it has one right answer, and explaining it well shows you understand how JavaScript actually schedules work.

How to answer these questions

For output questions, label each line as synchronous, microtask or macrotask before you say the answer. For design questions, state whether the operations depend on each other — dependent calls are awaited in sequence, independent ones go into Promise.all.

Closures appear inside almost every callback here, so if they still feel shaky, revise the closures and functions guide first.

Q1. What is the event loop in JavaScript?

The event loop is JavaScript's concurrency model. Because JS is single-threaded, the loop runs synchronous code first, then all microtasks (promises, queueMicrotask), then one macrotask (setTimeout, setInterval, I/O), and repeats.

console.log("1");
setTimeout(() => console.log("3"), 0);
Promise.resolve().then(() => console.log("2"));
// Output: 1  2  3

Interview note: This exact snippet is the most common output question. Explain it in order: 1 is synchronous, the promise callback is a microtask and runs before the timer, which is a macrotask — even with 0 ms.

Q2. What are promises in JavaScript?

A promise represents a value that may be available now, later or never. It has three states — pending, fulfilled and rejected — and you react to it with .then, .catch and .finally.

const p = new Promise((resolve, reject) => {
  setTimeout(() => resolve("done"), 1000);
});

p
  .then(val => console.log(val))   // "done"
  .catch(err => console.error(err))
  .finally(() => console.log("cleanup"));

Q3. What is a callback, and what is callback hell?

A callback is a function passed to another function and called when an operation finishes. Callback hell is deeply nested callbacks that become hard to read and handle errors in — promises and async/await flatten it.

// Callback hell (pyramid of doom)
getUser(id, (user) => {
  getPosts(user.id, (posts) => {
    getComments(posts[0].id, (comments) => {
      // deeply nested...
    });
  });
});

// Solution: async/await
const user = await getUser(id);
const posts = await getPosts(user.id);
const comments = await getComments(posts[0].id);

Q4. What is async/await and how does it relate to promises?

async/await is syntax over promises. An async function always returns a promise, and await pauses that function until the awaited promise settles — so asynchronous code reads like synchronous code.

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);
  }
}

Interview note: Trap: two awaits in a row run one after the other. If the calls are independent, start both and await Promise.all([...]) so they run in parallel.

Q5. How do you handle errors in promises and async/await?

With promises, add a .catch() at the end of the chain; with async/await, wrap the awaited calls in try/catch. An error thrown at any step skips to the nearest handler, and a rejection that nobody handles triggers an "unhandled rejection" warning.

// Promise chain
fetchUser()
  .then(user => fetchOrders(user.id))
  .then(showOrders)
  .catch(err => console.error("Failed:", err)); // catches any step

// async/await
async function load() {
  try {
    const user = await fetchUser();
    const orders = await fetchOrders(user.id);
    showOrders(orders);
  } catch (err) {
    console.error("Failed:", err);
  } finally {
    hideSpinner();
  }
}

Interview note: Trap: fetch does not reject on an HTTP 404 or 500 — it only rejects when the network fails. Check res.ok and throw the error yourself.

Q6. What is Promise.all() and when would you use it?

Promise.all() takes an array of promises and resolves when all of them resolve — or rejects as soon as any one rejects.

const [user, posts] = await Promise.all([
  fetch("/api/user").then(r => r.json()),
  fetch("/api/posts").then(r => r.json()),
]);
// Both requests run in parallel — not one after the other

Use it when several asynchronous operations are independent and you need all of their results.

Q7. What is the difference between Promise.race() and Promise.allSettled()?

Promise.race() settles with the first promise that settles, win or lose. Promise.allSettled() waits for all of them and returns an array of { status, value/reason } objects — it never rejects.

// race — timeout pattern
const result = await Promise.race([
  fetch("/api/slow"),
  new Promise((_, rej) => setTimeout(() => rej("timeout"), 3000)),
]);

// allSettled — you want every outcome, even if some fail
const results = await Promise.allSettled([p1, p2, p3]);
results.forEach(r => {
  if (r.status === "fulfilled") console.log(r.value);
  else console.warn(r.reason);
});

Q8. What does Promise.any() do?

Promise.any() resolves with the first promise that fulfils and ignores rejections along the way. It rejects only if every promise rejects, with an AggregateError that holds all the reasons.

const response = await Promise.any([
  fetch("https://mirror-1.example.com/data"),
  fetch("https://mirror-2.example.com/data"),
]);
// uses whichever mirror answers successfully first

Know the four combinators side by side: all (every promise must succeed), allSettled (wait for every result), race (first to settle, success or failure) and any (first success).

How to prepare

Write the classic ordering puzzle — console.log, setTimeout(…, 0), Promise.resolve().then(…) — and extend it with nested promises and await until you can predict every variant. Then build a small page that fetches two APIs in parallel, shows a spinner, and handles a failed request properly.

After this, the browser APIs and performance guide covers debouncing, Web Workers and lazy loading, which build on the same ideas.

Frequently Asked Questions

What is the difference between a microtask and a macrotask?
Microtasks are promise callbacks and queueMicrotask; macrotasks are setTimeout, setInterval, I/O and UI events. After each macrotask, the event loop empties the entire microtask queue before taking the next macrotask, which is why promise callbacks run before a 0 ms timer.
Is async/await better than promises?
async/await is built on promises, so it is not a replacement — it is easier-to-read syntax for the same thing. Use await for sequential steps and try/catch error handling; use Promise.all, race or any when you need several promises at once.
Does await block the whole program?
No. await pauses only the async function it is in. The rest of the program — other functions, event handlers, rendering — keeps running, and the function resumes as a microtask once the awaited promise settles.
How do I run several API calls in parallel?
Start all the calls first, then wait for them together: const [a, b] = await Promise.all([getA(), getB()]). Use Promise.allSettled instead if one failure should not cancel the others.
What happens if I forget to handle a rejected promise?
The error is not lost silently: browsers log an "unhandled promise rejection" and Node.js can terminate the process. Always end a promise chain with .catch() or wrap awaited calls in try/catch.
Is JavaScript truly asynchronous if it is single-threaded?
The JavaScript code runs on one thread, but the runtime — the browser or Node.js — performs timers, network and file work in the background. When that work finishes, its callback is queued and the event loop runs it on the main thread.

Want to Build Your Career in Java Full Stack with AI?

Join CodeBegun and train with working industry engineers — Explore the Java Full Stack program

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 28 November 2026 LinkedIn
Chat with us