Bird
0
0

Identify the error in this observable creation code:

medium📝 Debug Q14 of 15
Angular - RxJS and Observables Fundamentals
Identify the error in this observable creation code:
const obs = new Observable(subscriber => { subscriber.next('Hi'); subscriber.error('Oops'); subscriber.next('Bye'); });
ANo error, code is correct
BMissing subscriber.complete call
CObservable constructor syntax is wrong
DCalling subscriber.next after subscriber.error
Step-by-Step Solution
Solution:
  1. Step 1: Review observable error handling

    After calling subscriber.error(), the observable stops and no further next() calls run.
  2. Step 2: Check code sequence

    Here, subscriber.next('Bye') is called after error, which is invalid and ignored.
  3. Final Answer:

    Calling subscriber.next after subscriber.error -> Option D
  4. Quick Check:

    next after error is invalid [OK]
Quick Trick: No next() calls after error() [OK]
Common Mistakes:
MISTAKES
  • Thinking complete() is required after error()
  • Believing next() after error() runs
  • Confusing error() with complete()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes