JavaScriptMedium
Explain the concept of error propagation in JavaScript
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
Error propagation in JavaScript refers to how errors are passed through the call stack. When an error occurs in a function, it can be caught and handled using try...catch blocks. If not caught, the error propagates up the call stack until it is either caught or causes the program to terminate. For example:
js
function a() {
throw new Error("An error occurred");
}
function b() {
a();
}
try {
b();
} catch (e) {
console.error(e.message); // Outputs: An error occurred
}
