Skip to content
RED SAG Skills
mediumStudy question · answer published in System Design interview questions, so no pointsnodejsasync-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

Discussion 0

Join free to post in the discussion.

Related questions