freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #38 of 61

errors · stack traces

LambdaVSThe Mutator
Lambda saysThe stack trace shows the call path to an error — your first debugging clue.

Every Error carries a .stack string listing the function calls that led to it, newest first. Read it top-down to find where the throw happened and how you got there. In DevTools the trace is clickable. Don't strip stacks in production logs — they're how you reconstruct failures you can't reproduce.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleThrow from a nested function and log err.stack to see the call path.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o" style="white-space:pre-wrap"></pre>
<script>function a(){ b(); } function b(){ throw new Error('boom'); }
try{ a(); }catch(e){ document.getElementById('o').textContent=e.stack.split('\n').slice(0,4).join('\n'); }</script></body></html>
▶ Open the interactive comic issue
‹ Errors · Throwing · Custom Error ClassesClasses · The ES6 Syntax ›