Top RxJS Interview Questions (2020) | CodeUsingJava

Most frequently asked RxJS Interview Questions

What is RxJS?

  • RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code.
  • It is a powerful tool that turns complicated series of actions into concise code that is easy to manipulate.

What is Stream in RxJS?

  • A stream is a sequence of data elements made available over time.
  • A stream can be thought of as items on a conveyor belt being processed one at a time rather than in large batches.
  • The reason for it being called a stream is that you should think of the data as continuous and not really having an end, unless you explicitly define an end.

What is Observable?

  • Observable represents the idea of an invokable collection of future values or events.
  • In RxJS, we model asynchronous data streams using observable sequences or just called observables, too.

What is the benefits of RxJS Observables on promises?

  • Observables provide a feed, so that you can receive data from the same object multiple times.
  • So observables work like streams of data.
Cold and Hot Observables

What is the difference between Cold and Hot Observables ?

Cold Observables:
  • Cold observables start to run upon subscription, so observable sequence only starts pushing values to observers when subscribe is called.
Hot Observables:
  • Hot observables produce values even before subscriptions is made.
  • Hot observables such as mousemove events, stock pickers or WebSocket connections, are already produced in values even before subscription is active

What is the difference between React and RxJS ?

  • React is an open-source JavaScript library providing a view for data rendered as hyper text markup language.
  • RxJS stands for Reactive Extensions for JavaScript. It is a library for composing asynchronous programming in web development and event-based programs using observable sequences and LINQ-style query operators.

React RxJS

What are RxJS Operators ?

  • An operator is a method that acts on an Observable and changes the stream in some way.
  • The purpose of operator is to modify or filter the originally emitted values in a way that we normally need for the project tasks.

What are observers ?

  • 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.

What are the advantages of Observable over Promise ?

  • 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

What is Subscriptions ?

  • Subscriptions are objects returned when an Observable is subscribed.
  • Listening to the stream is called subscribing.

What is Subject ?

  • Subjects are unique types of Observers, that enables you to subscribe to other Observables and also listen to published data
  • Listening to the stream is called subscribing.