Skip to content
QuiznExam

RxJS & Observables in Angular

Test your knowledge of RxJS and Observables in Angular, including Observable creation, subscriptions, operators, Subjects, error handling, asynchronous data streams, and memory management.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What is an Observable in RxJS?

    • A. A class used only for database connections
    • B. A stream that can emit values over time
    • C. A replacement for Angular components
    • D. A synchronous variable that cannot change
    Show answer

    B. A stream that can emit values over time

    An Observable represents a stream of values that can be delivered over time to subscribed observers.

  2. 2. Which method is commonly used to listen to values emitted by an Observable?

    • A. listen()
    • B. observe()
    • C. subscribe()
    • D. connect()
    Show answer

    C. subscribe()

    The subscribe() method registers an observer to receive values, errors, and completion notifications from an Observable.

  3. 3. Which RxJS function creates an Observable that emits specified values sequentially and then completes?

    • A. of()
    • B. emit()
    • C. createValue()
    • D. sequence()
    Show answer

    A. of()

    The of() creation function emits each supplied argument as a separate value and then completes.

  4. 4. Which RxJS operator transforms each value emitted by an Observable?

    • A. filter()
    • B. map()
    • C. catchError()
    • D. take()
    Show answer

    B. map()

    The map() operator applies a transformation function to each value emitted by the source Observable.

  5. 5. Which RxJS operator emits only values that satisfy a specified condition?

    • A. map()
    • B. tap()
    • C. filter()
    • D. mergeMap()
    Show answer

    C. filter()

    The filter() operator forwards only those values that pass its predicate function.

  6. 6. Which RxJS operator is commonly used to switch to a new inner Observable and stop forwarding values from the previous inner Observable?

    • A. switchMap()
    • B. concatMap()
    • C. map()
    • D. reduce()
    Show answer

    A. switchMap()

    switchMap() switches to the latest inner Observable and unsubscribes from the previous inner subscription.

  7. 7. What is the primary purpose of a Subscription in RxJS?

    • A. To define an Angular route
    • B. To represent an active execution and allow it to be cancelled
    • C. To transform every emitted value
    • D. To create a component template
    Show answer

    B. To represent an active execution and allow it to be cancelled

    A Subscription represents a disposable resource associated with an Observable execution and can be unsubscribed when no longer needed.

  8. 8. Which RxJS type allows values to be multicasted to multiple subscribers and can also act as an Observable?

    • A. Subject
    • B. Promise
    • C. Subscription
    • D. Scheduler
    Show answer

    A. Subject

    A Subject is both an Observable and an Observer, allowing it to receive values and multicast them to its subscribers.

  9. 9. What distinguishes a BehaviorSubject from a regular Subject?

    • A. It cannot have subscribers
    • B. It stores and emits its current value to new subscribers
    • C. It only emits errors
    • D. It automatically completes after one value
    Show answer

    B. It stores and emits its current value to new subscribers

    A BehaviorSubject requires an initial value and immediately emits its current value to each new subscriber.

  10. 10. Which RxJS operator can be used to handle errors in an Observable pipeline?

    • A. catchError()
    • B. handleFailure()
    • C. errorMap()
    • D. recover()
    Show answer

    A. catchError()

    The catchError() operator intercepts an error and can replace the failed stream with another Observable.

  11. 11. Which RxJS operator is commonly used to perform a side effect without changing the emitted values?

    • A. map()
    • B. tap()
    • C. filter()
    • D. switchMap()
    Show answer

    B. tap()

    The tap() operator is intended for side effects such as logging or debugging while passing values through unchanged.

  12. 12. Which Angular service commonly returns an Observable when making HTTP requests?

    • A. Router
    • B. HttpClient
    • C. Renderer2
    • D. ChangeDetectorRef
    Show answer

    B. HttpClient

    Angular's HttpClient methods return Observables that emit HTTP response data or errors when subscribed to.

  13. 13. Which RxJS operator limits an Observable to its first specified number of emitted values?

    • A. take()
    • B. skip()
    • C. delay()
    • D. repeat()
    Show answer

    A. take()

    The take() operator forwards up to the specified number of values and then completes its output Observable.

  14. 14. Which Angular feature can automatically manage an Observable subscription in a template?

    • A. ngFor
    • B. AsyncPipe
    • C. ngSwitch
    • D. StylePipe
    Show answer

    B. AsyncPipe

    AsyncPipe subscribes to an Observable or Promise, exposes its latest value to the template, and automatically unsubscribes when the view is destroyed.

  15. 15. Which statement about Observables and Promises is correct?

    • A. Observables can never emit multiple values
    • B. Promises support repeated emissions over time
    • C. Observables can emit multiple values over time, while a Promise settles once
    • D. Observables must always execute synchronously
    Show answer

    C. Observables can emit multiple values over time, while a Promise settles once

    An Observable can emit zero or more values over time, whereas a Promise settles once with a fulfillment value or rejection reason.