What is the difference between callback and promise [duplicate]

Possible Duplicate:
What are the differences between Deferred, Promise and Future in Javascript?

Can someone point out what are the differences are between callbacks and promises? When should one use promise etc?

Also links on how to create and use promises will be appreciated.

Promises provide a more succinct and clear way of representing sequential asynchronous operations in javascript. They are effectively a different syntax for achieving the same effect as callbacks. The advantage is increased readability. Something like this


is much more readable then the equivalent of passing each of those individual functions as callbacks, like

    return bAsync(function(){
        return cAsync(function(){

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Cannot set cookies in Javascript

Similar Posts