LearnFrenzy
Sign in Take a free test

Scope and Hoisting · Find the Error · Question 4

Error: redeclaring the catch parameter Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

JavaScript refuses to run the code below. Which statement correctly describes the problem?

main.js
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links