Bird
0
0

What will be logged to the console when this code runs?

medium📝 Predict Output Q4 of 15
Angular - RxJS and Observables Fundamentals
What will be logged to the console when this code runs?
import { of } from 'rxjs';
const numbers$ = of(10, 20, 30);
numbers$.subscribe(value => console.log(value));
A10 20 30 (each on a new line)
B[10, 20, 30]
Cundefined
DError: subscribe is not a function
Step-by-Step Solution
Solution:
  1. Step 1: Understand the 'of' operator

    'of' creates an observable that emits each value in sequence: 10, then 20, then 30.
  2. Step 2: Analyze the subscription

    The subscribe callback logs each emitted value separately, so console logs 10, then 20, then 30 on new lines.
  3. Final Answer:

    10 20 30 (each on a new line) -> Option A
  4. Quick Check:

    Observable emits values one by one [OK]
Quick Trick: of() emits values sequentially to subscribe() [OK]
Common Mistakes:
MISTAKES
  • Expecting array output
  • Thinking subscribe returns array
  • Confusing with errors or undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes