Advertisement
728x90
An Observable is basically a function that can return a stream of values either synchronously or asynchronously to an observer over time. The consumer can get the value by calling subscribe() method.
Let's look at a simple example of an Observable
javascript
1import { Observable } from "rxjs";
2
3const observable = new Observable((observer) => {
4
5setTimeout(() => {
6 observer.next("Message from a Observable!");
7}, 3000);
8});
9
10observable.subscribe((value) => console.log(value));
Note: Observables are not part of the JavaScript language yet but they are being proposed to be added to the language
Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 65
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
408of476