Back to questions
JuniorTheoryCommon
What does the program print?
let s = "";
try {
s += "a";
throw new Error("x");
s += "b";
} catch (e) {
s += "c";
}
s += "d";
console.log(s);acd
- Expecting
abcd:throwstops thetryblock at once, sos += "b"never runs and the program jumps straight intocatch. - Expecting the program to stop after
catch: once the error is caught, the code after the wholetry…catchkeeps running, so"d"is added.
- What does the program print if the
throwline is removed? - What does
e.messagehold inside thecatchblock?