Understanding observer and Observables in RXJS

Yuvaraj S
2 min readOct 14, 2023

--

RXJS is Reactive Extensions Library for JavaScript. It composes asynchronous and event-based programs by using observable sequences.

What is Observables?
An observable is a data structure or a design pattern that represents a stream of data or events over time.
we can create an Observable by calling the Observable constructor and passing a function that defines how the Observable will emit data. This function takes an observer as an argument. The observer is an object with methods like next(), error(), and complete() for emitting data, handling errors, and signaling completion.

What is an Observer?
An observer is typically an object with one or more callback functions. The three primary callback functions you can define in an observer are:

  1. next(): This function is called when the Observable emits a new value. It receives the emitted value as its argument.
  2. error(): This function is called if an error occurs during the execution of the Observable. It receives the error object as its argument.
  3. complete(): This function is called when the Observable completes, indicating that it has finished emitting data.

We have created a stream in above example code. now in order to access it we subscribe to it. Now the output will be 0,1,3,4,5 from next block one after the other and completes by calling callback complete() function.

— — — — — — — — — — — — — — END OF THE BLOG — — — — — — — — — — — — — -

Full series link of RXJS OPERATORS

--

--

Yuvaraj S

Frontend Developer with 6years of experience, I write blogs that are [Easy words + Ground Level Code + Live Working Link]. Angular | React | Javascript | CSS