Bird
0
0

Consider this code:

medium📝 component behavior Q5 of 15
Node.js - Error Handling Patterns
Consider this code:
class AppError extends Error { constructor(message, code) { super(message); this.code = code; } } const err = new AppError('Failed', 500); console.log(err.code);
What is the output?
AError
BFailed
Cundefined
D500
Step-by-Step Solution
Solution:
  1. Step 1: Understand constructor parameters

    The constructor sets this.code to the passed code value (500).
  2. Step 2: Check console.log output

    Logging err.code outputs 500 as assigned.
  3. Final Answer:

    500 -> Option D
  4. Quick Check:

    Custom property access = 500 [OK]
Quick Trick: Custom properties are accessible on error instances [OK]
Common Mistakes:
  • Confusing message with code property
  • Expecting code to be undefined
  • Assuming code is a built-in Error property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes