JavaScript · Middle · Question 51 of 75

In what order are the lines printed?

setTimeout(() => console.log("timeout"));
queueMicrotask(() => console.log("microtask"));
console.log("sync");

Explanation

Synchronous code runs first, then the whole microtask queue (promise callbacks, queueMicrotask), and only then the next macrotask such as a timer.

Further reading

Problem with a question

JavaScript · Middle · question 51

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz