Bird
0
0

Consider this code:

medium📝 component behavior Q5 of 15
Node.js - Error Handling Patterns
Consider this code:
try {
  JSON.parse('invalid');
  console.log('Parsed');
} catch (err) {
  console.log('Error:', err.name);
}

What will be printed?
AError: ReferenceError
BParsed
CError: SyntaxError
DNothing, program crashes
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSON.parse behavior

    Parsing invalid JSON throws a SyntaxError synchronously.
  2. Step 2: Catch block handles the error

    The catch block prints the error name, which is 'SyntaxError'.
  3. Final Answer:

    Error: SyntaxError -> Option C
  4. Quick Check:

    JSON.parse error caught = A [OK]
Quick Trick: Invalid JSON throws SyntaxError caught by catch [OK]
Common Mistakes:
  • Expecting 'Parsed' to print
  • Confusing error types
  • Assuming program crashes without catch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes