Level 20

Awaiting a timer

An async function sleeps for 10ms with a promise around setTimeout.

const sleep = (ms) => new Promise((r) => setTimeout(r, ms));async function run() {  console.log('start');  await sleep(10);  console.log('woke up');}run();console.log('main done');

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…