Skip to content
loading...

re: Callbacks vs Promises in JavaScript VIEW POST

FULL DISCUSSION
 

Hi there and thanks for your article. I didn't know about the Promise.allSettled and your article just made me discover this!

I think your example:

function getMoneyBack(money, callback) {
  if (typeof money !== 'number') {
    callback(null, new Error('money is not a number'))
  } else {
    callback(money)
  }
}

const money = getMoneyBack(1200)
console.log(money)

Is missing its callback:

function getMoneyBack(money, callback) {
  if (typeof money !== 'number') {
    callback(null, new Error('money is not a number'))
  } else {
    return callback(money)
  }
}

const money = getMoneyBack(1200, function(money) {
    return money * 1.2; // applying some increase
})

console.log(money);
code of conduct - report abuse