OutputNot attempted
catch parameter scope
(() => { let x, y; try { throw new Error(); } catch (x) { (x = 1), (y = 2); console.log(x); } console.log(x); console.log(y);})();Spaces and quote style don’t matter · write a thrown error as TypeError
Ctrl Enter
Show answer & explanation
The expected output comes from actually running the snippet; opening this shows it next to the explanation.
The catch parameter x is a NEW binding scoped to the catch block, shadowing the outer x. Assigning x = 1 changes the catch-block x only; y has no shadow, so the outer y becomes 2.