0

I want to know what the difference between promises and a traditional callback is. If they are the same then why do we use promises or if they are not same which is the best approach

using callback functionality

$.get('userDetails', {'name': 'joe'}, function(data) {
    $('#userAge').text(data.age);
});

using promises functionality

$http.get('userDetails', {'name': 'joe'})
    .then(function(response) {
        $('#userAge').text(response.age);
    });
Epi
  • 322
  • 2
  • 15
  • Promises are significantly more versatile because they can be chained and any rejections get passed down the chain. Any error in a callback never gets caught anywhere. Really doesn't seem like you did much research on this before asking – charlietfl May 08 '17 at 06:27
  • [how-much-research-effort-is-expected-of-stack-overflow-users](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) – charlietfl May 08 '17 at 06:32
  • Promises are not callbacks ... the functions passed to `.then/.catch` are called back when the promise resolves, so yes, they are callbacks, but Promises themselves are not callbacks – Jaromanda X May 08 '17 at 06:38

0 Answers0