Bird
0
0

Given this Angular observable code:

medium📝 component behavior Q4 of 15
Angular - RxJS and Observables Fundamentals
Given this Angular observable code:
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
B1 2
C3
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand observable emission and completion

    The observable emits 1 and 2, then calls complete, which stops further emissions.
  2. Step 2: Analyze the emission after complete

    The call to subscriber.next(3) after complete is ignored and does not emit.
  3. Final Answer:

    1 2 -> Option B
  4. Quick Check:

    Emissions before complete = A [OK]
Quick Trick: No values emit after complete() is called. [OK]
Common Mistakes:
MISTAKES
  • Expecting values after complete()
  • Thinking complete() emits a value
  • Ignoring the order of emissions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes