DEV Community

Discussion on: Callbacks vs Promises in JavaScript

Collapse
 
aminnairi profile image
Amin

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);