Bird
0
0

Consider the following Angular RxJS code:

medium📝 component behavior Q4 of 15
Angular - RxJS Operators
Consider the following Angular RxJS code:
import { of, combineLatest } from 'rxjs';

const obs1 = of(3, 4);
const obs2 = of('X', 'Y');

combineLatest([obs1, obs2]).subscribe(console.log);

What will be the output logged to the console?
A[4, 'Y']
B[3, 'X'] and then [4, 'Y']
C[3, 'Y'] and then [4, 'X']
D[3, 'X'] only
Step-by-Step Solution
Solution:
  1. Step 1: Understand of emissions

    of(3,4) emits 3 then 4 synchronously, same for of('X','Y').
  2. Step 2: Behavior of combineLatest

    combineLatest waits for each observable to emit at least once, then emits the latest values whenever any observable emits.
  3. Step 3: Synchronous emissions

    Since both observables emit synchronously, the last emitted values are 4 and 'Y'. combineLatest will emit only once with these latest values.
  4. Final Answer:

    The console logs [4, 'Y'] once, matching [4, 'Y'].
  5. Quick Check:

    Synchronous of emissions cause combineLatest to emit only the last combined values. [OK]
Quick Trick: Synchronous observables emit last combined values once [OK]
Common Mistakes:
MISTAKES
  • Assuming multiple emissions from combineLatest with synchronous observables
  • Confusing emission order of combineLatest
  • Expecting combineLatest to emit on each individual emission

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes