Guest practice: this set is not saved and does not count.
What does this log?
try { JSON.parse("{bad json}"); } catch (e) { console.log(e.name, e instanceof SyntaxError); }
If a script has a syntax error on line 20, a console.log("Before") on line 1 never prints.
console.log("Before")
function average(list) { if (list.length === 0) { throw new RangeError("Cannot average an empty list"); } let sum = 0; for (const n of list) sum += n; return sum / list.length; } try { console.log(average([90, 80])); console.log(average([])); } catch (e) { console.log(e.name + ": " + e.message); }
85
NaN
RangeError: Cannot average an empty list
undefined
RangeError
A try...catch placed around a setTimeout call will catch an error thrown later inside the timer's callback.
try...catch
setTimeout
function inner() { return null.x; } function outer() { return inner(); } try { outer(); } catch (err) { console.log(typeof err.stack, err.name, err instanceof TypeError); }
Click a question to go back and check it. After you submit, you will see the right answer and an explanation for every question. As a guest, nothing is saved.
Check my answers