Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Error Handling in Async JavaScript

MediumCoding00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to your interview.

The question is on your right: Error Handling in Async JavaScript. Take a moment with it first.

Talk your thinking through with me if you like - when you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes). Discussion and graded submissions share your five interviewer interactions, so spend them well.

You need to log in / sign up to chat or submit.

Problem

Context

You’re building a fintech payments web app serving 5M+ monthly active users. A single unhandled async error in the checkout flow can cause failed payments, duplicate charges, or missing receipts—creating real revenue loss and regulatory risk. In modern JavaScript, most failures happen asynchronously (network timeouts, rejected Promises, event handlers), and error handling differs depending on whether you use callbacks, Promises, or async/await.

Core Question

Explain how to handle errors in asynchronous JavaScript across the major async models. Your answer should cover:

  1. Callbacks & event loop: Why a try/catch around an async callback often doesn’t catch errors thrown inside the callback, and how errors should be surfaced instead.
  2. Promises: How rejections propagate through .then() chains, the role of .catch(), and how to avoid “swallowed” errors.
  3. async/await: How await maps to Promise rejection, how try/catch works here, and patterns for handling partial failures (e.g., Promise.all vs Promise.allSettled).
  4. Global handling: When (and when not) to use window.onerror, unhandledrejection, or Node’s process.on('unhandledRejection') as a safety net.

Scope Guidance

Assume the interviewer expects staff-level depth: describe error propagation semantics, common pitfalls (missing return, forgetting await, mixing callbacks with Promises), and production patterns (timeouts, retries, cancellation/AbortController, error normalization). Include short code snippets to illustrate correct and incorrect patterns.