Bird
0
0

Given this Angular code snippet:

medium📝 component behavior Q13 of 15
Angular - RxJS and Observables Fundamentals
Given this Angular code snippet:
const obs = new Observable(subscriber => {
subscriber.next(1);
subscriber.next(2);
subscriber.complete();
subscriber.next(3);
});
obs.subscribe(value => console.log(value));

What will be printed in the console?
A1 2 3
B3
C1 2
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand observable emissions

    The observable emits 1, then 2, then calls complete(). After completion, emissions stop, so 3 is ignored.
  2. Step 2: Determine console output

    The subscriber logs values 1 and 2 only. Value 3 is not emitted because the observable is completed before it.
  3. Final Answer:

    1 2 -> Option C
  4. Quick Check:

    Complete stops emissions = 1 2 [OK]
Quick Trick: complete() stops further emissions [OK]
Common Mistakes:
MISTAKES
  • Expecting value after complete()
  • Thinking all next() calls run regardless
  • Ignoring complete() effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes