cf.completefrontend

Predict the outputMedium

What does this log when forEach is given an async callback?

What does this log?
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
 
async function main() {
  const done = [];
  [30, 10, 20].forEach(async (ms) => {
    await wait(ms);
    done.push(ms);
  });
  console.log("after forEach:", done);
 
  await wait(50);
  console.log("later:", done);
}
 
main();

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…