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)Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Promise and setTimeout orderBackend Developer
- Python default list surpriseBackend Developer
- Checking a key by its valueBackend Developer
- Two awaits that could run togetherBackend Developer
- A 64-bit id changes after parsingBackend Developer
- Webhook signature never matchesBackend Developer
- Pool runs dry after some errorsBackend Developer