Observable vs Promise...Which is Better?

I understand both are used to handle async activity in JavaScript. I am curious as to whether or not Promises are even worth it with RxJs library and Observables.


Answers

K
Katelynn_Treutel

It depends. While it's true that observables can do everything promises can, it's not necessarily ALWAYS better to use observables. Observables were popularized by frameworks like Angular for their event based handling of async activity. Specifically RxJs did a good job of implementing the observer design pattern and it's used widely today throughout the JavaScript community for reactive programming.

This is not to say that Observables have not been abused. Sometimes a Promise is better. A Promise doesn't require any third party libraries (like RxJs)...instead the Promise is native with JavaScript ES6.

So obviously it's not a matter of BETTER or WORSE. It's more what is specific to your applications needs. Realistically you can use both to achieve the same thing across the board. But Observables can be overengineering a rather simple task at times.