JavaScript Event Loop & Microtasks Introduction Quiz
Answer 50 questions about the JavaScript event loop, call stack, macrotasks, microtasks, promise timing, rendering, async APIs, starvation risks, and debugging workflows.
Question 1
What does the call stack track in JavaScript engines?
Question 2
Why must the call stack be empty before the event loop pulls the next macrotask?
Question 3
What prints?
function second() {
console.log('second')
}
function first() {
console.log('first')
second()
}
first()Question 4
What happens if a function recursively calls itself without a base case?
Question 5
What prints?
console.log('A')
setTimeout(() => console.log('B'), 0)
console.log('C')Question 6
What is the main job of the event loop?
Question 7
Why is the event loop crucial for non-blocking behavior?
Question 8
Which statement describes a typical loop tick?
Question 9
What prints?
console.log('loop start')
queueMicrotask(() => console.log('microtask'))
console.log('loop end')Question 10
Why do browsers sometimes defer rendering until after microtasks run?
Question 11
Which of these schedules a macrotask?
Question 12
What prints?
console.log('start')
setTimeout(() => console.log('timer'), 0)
Promise.resolve().then(() => console.log('promise'))
console.log('finish')Question 13
Why are macrotasks sometimes called tasks?
Question 14
What prints?
setTimeout(() => console.log('T1'), 0)
setTimeout(() => console.log('T2'), 0)
console.log('sync')Question 15
Why might you split heavy work across multiple macrotasks?
Question 16
Which API adds a callback to the microtask queue?
Question 17
What prints?
Promise.resolve().then(() => console.log('microtask 1'))
Promise.resolve().then(() => console.log('microtask 2'))
console.log('sync')Question 18
Why must engines fully drain the microtask queue before rendering?
Question 19
What prints?
queueMicrotask(() => {
console.log('A')
queueMicrotask(() => console.log('B'))
})
console.log('sync')Question 20
How do MutationObserver callbacks behave?
Question 21
When does a promise reaction callback run?
Question 22
What prints?
const p = Promise.resolve('done')
p.then(value => console.log(value))
console.log('after')Question 23
What prints?
Promise.resolve().then(() => console.log('first then'))
Promise.resolve().then(() => console.log('second then'))
console.log('sync work')Question 24
Why should you avoid long microtask chains that never yield?
Question 25
How does async/await relate to promise timing?
Question 26
Which typically runs first: a 0ms setTimeout or Promise.resolve().then?
Question 27
What prints?
setTimeout(() => console.log('timeout'), 0)
Promise.resolve().then(() => console.log('promise'))
console.log('sync')Question 28
What prints?
Promise.resolve().then(() => console.log(1))
setTimeout(() => console.log(2), 0)
Promise.resolve().then(() => console.log(3))Question 29
Why is setImmediate in Node.js considered a macrotask?
Question 30
How can you ensure a timer runs after the current microtasks but before rendering?
Question 31
When do browsers typically run requestAnimationFrame callbacks?
Question 32
Why might layout thrashing occur?
Question 33
What prints?
requestAnimationFrame(() => console.log('paint' ))
console.log('sync work')Question 34
How can microtasks delay rendering indefinitely?
Question 35
Why is yielding via requestIdleCallback useful?
Question 36
How do fetch() responses enter the event loop?
Question 37
What prints?
async function run() {
console.log('before fetch')
await Promise.resolve()
console.log('after await')
}
run()
console.log('global')Question 38
Why does setInterval use the macrotask queue?
Question 39
How do Web Workers interact with the event loop?
Question 40
Why should long-running synchronous work be moved to a worker when possible?
Question 41
What is microtask starvation?
Question 42
What prints?
let count = 0
function spin() {
if (count < 3) {
count += 1
queueMicrotask(spin)
}
}
queueMicrotask(spin)
console.log('done scheduling')Question 43
How can you avoid microtask starvation when chaining promise reactions?
Question 44
Why might microtask starvation be hard to detect?
Question 45
Which technique helps limit microtask loops?
Question 46
How can the Performance panel help debug event loop stalls?
Question 47
Why is logging timestamps useful when tracking async order?
Question 48
What prints?
console.log('trace 1')
setTimeout(() => console.log('trace 2'))
Promise.resolve().then(() => console.log('trace 3'))
console.log('trace 4')Question 49
What DevTools feature helps inspect microtask queues?
Question 50
Why should you annotate tricky asynchronous flows with inline comments?
