Bird
0
0

Identify the error in this Angular RxJS code using forkJoin:

medium📝 Debug Q14 of 15
Angular - RxJS Operators
Identify the error in this Angular RxJS code using forkJoin:
import { forkJoin, of } from 'rxjs';

const obs1 = of(1, 2);
const obs2 = of('A', 'B');

forkJoin([obs1, obs2]).subscribe(console.log);
ANo error; code works and logs [2, 'B']
BforkJoin requires observables to emit only once; multiple emissions cause error
CforkJoin does not accept an array of observables
DforkJoin emits on every emission, so output is multiple arrays
Step-by-Step Solution
Solution:
  1. Step 1: Check forkJoin input and behavior

    forkJoin accepts an array of observables and waits for all to complete, then emits an array of their last emitted values.
  2. Step 2: Verify observables emitting multiple values

    Observables emitting multiple values are allowed; forkJoin only emits after completion with last values. Here, obs1 emits 1 then 2, obs2 emits 'A' then 'B'. forkJoin emits [2, 'B'] once.
  3. Final Answer:

    No error; code works and logs [2, 'B'] -> Option A
  4. Quick Check:

    forkJoin waits for last values, no error [OK]
Quick Trick: forkJoin accepts arrays and emits last values after completion [OK]
Common Mistakes:
MISTAKES
  • Thinking forkJoin errors on multiple emissions
  • Believing forkJoin emits multiple times
  • Assuming forkJoin cannot take arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes