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.
Explain how to handle errors in asynchronous JavaScript across the major async models. Your answer should cover:
try/catch around an async callback often doesn’t catch errors thrown inside the callback, and how errors should be surfaced instead..then() chains, the role of .catch(), and how to avoid “swallowed” errors.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).window.onerror, unhandledrejection, or Node’s process.on('unhandledRejection') as a safety net.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.