Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Angular - RxJS and Observables Fundamentals
What is wrong with this code?
const subject = new BehaviorSubject();
subject.subscribe(value => console.log(value));
ABehaviorSubject requires an initial value in constructor.
Bsubscribe() must be called after next().
CBehaviorSubject cannot be subscribed to directly.
Dnext() must be called before creating BehaviorSubject.
Step-by-Step Solution
Solution:
  1. Step 1: Check BehaviorSubject constructor requirements

    BehaviorSubject requires an initial value passed to its constructor.
  2. Step 2: Validate subscription timing

    Subscription can happen anytime; no need to call next() first.
  3. Final Answer:

    BehaviorSubject requires an initial value in constructor. -> Option A
  4. Quick Check:

    BehaviorSubject initial value mandatory = B [OK]
Quick Trick: BehaviorSubject must be created with an initial value. [OK]
Common Mistakes:
MISTAKES
  • Omitting initial value in BehaviorSubject
  • Thinking subscription order matters
  • Confusing BehaviorSubject with Subject

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes