Question 3
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
function withdraw(balance, amount) {
if (amount > balance) throw
new Error("Insufficient balance");
return balance - amount;
}
- A It throws the error normally
- B It throws undefined
- C It returns balance - amount
- D SyntaxError: no line break is allowed between throw and its expression (automatic semicolon insertion rules) Correct
Correct Answer: Option D
Like return, throw must have its expression on the same line. Unlike return (which would return undefined), a bare throw is a syntax error.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!