Search⌘ K
AI Features

Introducing Rx Concepts

Explore the key concepts of RxJS and observables. Understand the differences between variables, arrays, promises, and observables, and learn how observables help manage asynchronous event streams in reactive programming.

Rx basics

It’s time for Rx basics. First, we need to figure out where observables stand in the greater context of the JavaScript landscape.

Variable

This is an example of a variable:

TypeScript 3.3.4
let myVar = 42;
console.log(myVar);

As you probably know, a variable contains a single value, and that value can be used immediately after declaration. Variables are pretty simple. On the other hand, we have arrays.

Array

This is an example of an array.

TypeScript 3.3.4
//Array represents a collection of values
let myArr = [42, 'hello world', NaN];
console.log(myArr);

This array represents a collection of values. Like the humble variable, an array also contains its data at the moment of creation.

Promise

If all of programming just used the above two concepts, life would be pretty easy. Everything needed to run a program would be immediately available when the program started.

Unfortunately, there are times when the data the program needs ...