JavaScript Interview Question #152
What is an unhandled Promise rejection?
Performance, Browser APIs, Rendering & Modern Web Architecture Senior Advanced
Quick Interview Answer
An unhandled Promise rejection occurs when a Promise rejects and the application does not attach an appropriate rejection handler within the runtime's handling rules. In browsers and server runtimes this can produce warnings, diagnostic events, or process-level consequences depending on the environment.
Detailed Explanation
An unhandled Promise rejection occurs when a Promise rejects and the application does not attach an appropriate rejection handler within the runtime's handling rules. In browsers and server runtimes this can produce warnings, diagnostic events, or process-level consequences depending on the environment.
Production code should deliberately handle expected failures and allow unexpected failures to reach a centralized logging or error boundary rather than silently ignoring them.
Code Example
async function load() {
throw new Error("Request failed");
}
// Bad if nobody handles the returned Promise:
// load();
// Better:
load().catch(error => {
console.error("Load failed:", error);
});