Skip to content
RED SAGSkills
medium10 pts · first answer countsnodejsasync-programmingdebugging

Async callback inside forEach

getPrice(id) returns a promise that resolves to 10 after a short delay. What does this print?

async function totalPrice(ids) {
  let total = 0
  ids.forEach(async (id) => {
    total += await getPrice(id)
  })
  return total
}

totalPrice([1, 2, 3]).then(console.log)
Choose one answer