Angular

RxJS Fundamentals

Observables, observers, subscriptions, subjects, operators basics, cold vs hot observables, unsubscribe strategies

22 interview questionsยท
Mid-Level
1

What is an Observable in RxJS?

Answer

An Observable is a lazy collection of multiple values over time. It represents a data stream that can emit zero, one, or multiple values synchronously or asynchronously. Unlike Promises which emit a single value, Observables can emit multiple values and support cancellation via unsubscribe.

2

What is the main difference between an Observable and a Promise?

Answer

Observables can emit multiple values over time and are cancellable with unsubscribe, while Promises emit a single value (resolve or reject) and cannot be cancelled once started. Additionally, Observables are lazy (execute only on subscription) while Promises are eager (execute immediately).

3

How to create a simple Observable that emits values 1, 2, 3?

Answer

The of() method from RxJS creates an Observable that emits the provided values as arguments synchronously, then completes. It's the simplest creation operator for known values. Alternatives: from() to convert an array/iterable, or new Observable() for full control over the emission flow.

4

What happens if you don't unsubscribe from an Observable?

5

What is a Subject in RxJS?

+19 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free