Avatar ·

What is the difference between Subject and BehaviorSubject in RxJS?

Hi everyone! I just started learning RxJS in Angular and got confused about the difference between Subject and BehaviorSubject. They both seem to be used for creating Observables, but I don't understand when to use which. I have a service for managing user state: ```typescript import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class UserService { private userSubject = new Subject(); user$ = this.userSubject.asObservable(); login(user: User) { this.userSubject.next(user); } logout() { this.userSubject.next(null); } } ``` The problem occurs when I subscribe to `user$` before `login()` or `logout()` has been called. The subscriber simply doesn't receive any value, even