Bird
0
0

What will be printed to the console when running this code?

medium📝 component behavior Q4 of 15
Node.js - Error Handling Patterns
What will be printed to the console when running this code?
Promise.reject('Oops').catch(() => console.log('Handled')).then(() => console.log('Done'));
A'Handled' followed by 'Done'
B'Done' only
C'Oops' followed by 'Handled'
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Promise.reject triggers rejection

    The Promise is rejected with 'Oops'.
  2. Step 2: catch handles the rejection

    The catch runs and logs 'Handled'.
  3. Step 3: then runs after catch

    Since catch handled the error, the chain continues and then logs 'Done'.
  4. Final Answer:

    'Handled' followed by 'Done' -> Option A
  5. Quick Check:

    Does catch handle error and then continue? Yes. [OK]
Quick Trick: catch handles error, then continues to then [OK]
Common Mistakes:
  • Assuming catch stops the chain
  • Expecting 'Oops' to be logged
  • Believing no output occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes