Code Lab

Output order

EasyAsync code3 min

What does this code print? Write one line for each console log call.

console.log('sync 1');
setTimeout(() => {
  console.log('timeout');
}, 0);
Promise.resolve().then(() => {
  console.log('then');
});
console.log('sync 2');

Program

console.log('sync 1');
setTimeout(() => {
  console.log('timeout');
}, 0);
Promise.resolve().then(() => {
  console.log('then');
});
console.log('sync 2');

Source

Predict the output
Loading the editor...
Run your code to see the test results here.