Search code examples
javascriptpromisees6-promise

What are the differences between observables and promises in JavaScript?


So i've read that observables are looking to overtake promises in terms of usage in some of upcoming JavaScript MVC's:

What is the difference between observables and promises?

Updated: Apologies! removed my falsy statement.


Solution

  • What is the difference between observables and promises?

    Simply put: A promise resolves to a single value asynchronously, an observable resolves to (or emits) multiple values asynchronously (over time).

    Concrete examples:

    • Promise: Response from an Ajax call
    • Observable: Click events

    More information can be found here: http://reactivex.io/intro.html

    i've read that observables are looking to overtake promises

    Unlikely. Observables might be the better solution to certain problems, but that doesn't make promises obsolete (if that's what you mean).