Promises and observables are for handling asynchronous execution in javascript.
Here is a sample code using Promises
Now the same using rxjs observables
Em, you may ask that there is no really difference. The difference is that with observables you are able to use RXJS operators which will save you plenty of time. With Promises, for example, if you want to make transformations with the received data, or filter it, you need to create helper functions, and with RXJS there are already dozens of helpful operators which can do that and more.
The other issue with Promises is so called "promise hell" when you chain multiple Promises. The code soon will get ununderstandable and ugly. With RXJS operators like flatMap() or switchMap() you don't have to worry about it.
Consider this pseudo code with Promises
Now it looks ok, but have you seen 3 closing braces already ? Image that //some logic part is going to be many lines of code and you see that this will get messy very easily.
Now the same with rxjs
Hmm, we still have 3 parts inside connectDatabase, but now we won't be confused and think about which closing brace is for which then. And each //some logic is inside its own switchMap which also makes it easy to maintain this code.
P.S.
Remember, you can transform any promise to observable with from() operator.