Bird
0
0

Consider this code:

medium📝 Predict Output Q5 of 15
Angular - RxJS and Observables Fundamentals
Consider this code:
const source$ = new Observable(observer => {
  observer.next('Hello');
  observer.complete();
  observer.next('World');
});
source$.subscribe(value => console.log(value));

What will be printed to the console?
AWorld
BHello World
CNo output
DHello
Step-by-Step Solution
Solution:
  1. Step 1: Understand observer behavior

    After calling observer.complete(), the observable stops emitting further values.
  2. Step 2: Analyze emitted values

    Only 'Hello' is emitted before complete(), so only 'Hello' is logged.
  3. Final Answer:

    Hello -> Option D
  4. Quick Check:

    complete() stops further emissions [OK]
Quick Trick: complete() stops emissions after it runs [OK]
Common Mistakes:
MISTAKES
  • Expecting 'World' after complete()
  • Thinking all next() calls run
  • Assuming no output if complete() called

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes