Output: await inside a forEach callback, followed by a log after the loop
MediumP1Output
What does this code print?
1const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));2async function main() {3 [1, 2, 3].forEach(async (n) => {4 await wait(10);5 console.log('item', n);6 });7 console.log('done');8}9main();
Saved automatically
One line per console.log. Arrays as [1, 2, 3], objects as { a: 1 }, an uncaught error as Uncaught TypeError: message (Chrome and Node wording).
Hints
Saved automatically