Question 4
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
try {
JSON.parse("{bad json}");
} catch (err) {
let err = "Invalid input";
console.log(err);
}
- A It prints Invalid input
- B It prints the SyntaxError message
- C ReferenceError
- D SyntaxError: err is already declared as the catch parameter in this block Correct
Correct Answer: Option D
The catch parameter belongs to the catch block, so let err in the same block is a duplicate. Use another name: const message = "Invalid input";
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!