JavaScript › Error Handling

What is error propagation, and how does an uncaught error in a nested function behave?

Intermediate

Answer

If a function doesn't catch an error itself, it automatically propagates up the call stack to the nearest enclosing try/catch (or crashes the program/rejects the promise if none exists) — you don't need to manually re-throw at every level.
function inner() { throw new Error('boom'); }
function outer() { inner(); } // doesn't need its own try/catch
try {
  outer();
} catch (err) {
  console.log('Caught:', err.message); // 'Caught: boom'
}
Real-world example Letting a deeply nested validation function throw, and catching it once at the top-level request handler.

Common follow-ups: What is the 'error boundary' pattern, and how does it relate to this in UI frameworks?