RxJS Interview Questions and Answers
Question - 31 : - What do you understand by to be Resilient for a Reactive System?
Answer - 31 : -
To be Resilient for a Reactive System means the system will stay responsive if it gets any chance of failure. Any system that is not resilient will be unresponsive after a failure. Resilience is achieved by replication, containment, isolation and delegation. Failures are contained within each component, isolating components from each other, thereby ensuring that parts of the system can fail and recover without compromising the entire system.
Question - 32 : - What are the biggest advantages of Reactive Programming?
Answer - 32 : -
Advantages of using Reactive Programming
- Reactive programming provides a lot of operators that can simplify our work.
- Reactive programming is very simple to compose streams of data.
- It can be used to avoid "callback problems".
- In Reactive programming, it is very simple to do async and threaded task.
- It makes complex threading very easy.
- By using Reactive programming, we can get a more cleaner and readable code base.
- In Reactive programming, it is easy to implement back-pressure.
Question - 33 : - What is Observers and Subscriptions?
Answer - 33 : -
Observers and Subscriptions are related to the concept of Observable.
Observers:
Observer is a set of callbacks that know how to listen to the values of the Observable.
- Observers are also referred to as listeners (or consumers)
- Observers may listen or subscribe to the data being observed.
Subscription:
Subscription is an observable execution
- Subscriptions are objects returned when an Observable is subscribed.
- Subscription is useful mainly to cancel the execution
Question - 34 : - What is RxJS Map and What is Higher-Order Observable Mapping?
Answer - 34 : -
RxJS map operator lets us project the payload of the Observable into something else.The power of Observables is revealed when you start using Rx operators to transform, combine, manipulate, and work with sequences of items emitted by Observables.
Question - 35 : - When we use the switchMap, mergeMap and concatMap?
Answer - 35 : -
concatMap(), mergeMap(), switchMap() and exhaustMap(). All of these operators are flattening operators used to flatten observables, but they are applicable in very different scenarios. switchMap and mergeMap are probably going the be the most powerful and frequently used operators. Its is thereby critical to understand the difference between the two in order to spend less time debugging code.
Question - 36 : - What is RxJS mergeMap?
Answer - 36 : -
mergeMap : mergeMap allows for multiple inner subscriptions to be active at a time. Because of this, one of the most common use-case for mergeMap is requests that should not be canceled.
Question - 37 : - What is RxJS switchMap?
Answer - 37 : -
switchMap : Simply put, it means switching to a new observable. The previous inner observable (result of the function you provided) is canceled for each emission and the new observable is subscribed.
Question - 38 : - When we use zip and combineLatest and withLatestFrom?
Answer - 38 : -
zip and combineLatest are functions and withLatestFrom is operator that allows to combine a few observable sequences in a different ways, that are really helpful in real world application.
Composing functions and operators usually accept observables as their params and also they return observable that emits array with values produced by argument observables. This result observable emission logic is different depending on which operator or function we use
Question - 39 : - What are observers ?
Answer - 39 : -
- Observer is a set of callbacks that are informative to listen to the values of the Observable.
- Observers may listen or subscribe to the data being observed.
Question - 40 : - What are the advantages of Observable over Promise ?
Answer - 40 : -
- An Observable is like a Stream. It enables to pass zero or more events where the callback is called for each event.
- Observable is preferred over Promise because it provides the features of Promise and more.
- With Observable we can handle a single or multiple events.
- Observable also has the advantage over Promise to be cancelable.
- Observable allows lazy initialization.
- Observable allows to format data
- Observable provides operators like map, forEach, reduce etc