The Event Loop — One Thread, No Blocking — Concept Check
Questions on The Event Loop — One Thread, No Blocking. JavaScript runs your code on a single thread. Asynchronous work is handed to the runtime and its callback is queued, so nothing runs concurrently with your code — it runs after it.
Questions in this quiz
7 questions on The Event Loop — One Thread, No Blocking — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A JavaScript function is running a long synchronous loop. What is a likely consequence?
- AThe loop automatically yields to allow rendering.
- BThe loop runs in parallel with other code.
- CThe UI becomes unresponsive until the loop finishes.
- DAsync functions can run simultaneously with the loop.
2.In JavaScript, what happens when a `setTimeout(fn, 0)` is called?
- AIt blocks the current execution until it runs.
- BIt runs immediately after the current code finishes.
- CIt runs after the current stack and all pending promises.
- DIt runs in parallel with the current code.
3.A promise chain continuously adds microtasks. What effect does this have on macrotasks?
- AMacrotasks interrupt the microtasks.
- BMacrotasks are delayed until all microtasks complete.
- CMicrotasks and macrotasks run simultaneously.
- DMacrotasks run in parallel with microtasks.
4.Why does a heavy computation in JavaScript make the UI unresponsive?
- AJavaScript runs on a single thread, blocking UI updates.
- BJavaScript lacks async capabilities for heavy tasks.
- CJavaScript prioritizes UI rendering over computations.
- DJavaScript automatically pauses for UI updates.
5.What is the output order of the following code: `setTimeout(() => console.log('timeout')); Promise.resolve().then(() => console.log('promise')); queueMicrotask(() => console.log('microtask'));`
- Atimeout, microtask, promise
- Bpromise, microtask, timeout
- Cmicrotask, promise, timeout
- Dtimeout, promise, microtask
6.In a Node.js environment, what runs before promise callbacks?
- AqueueMicrotask
- Bprocess.nextTick
- CsetTimeout
- DsetImmediate
7.What happens when you continuously add microtasks in a JavaScript function?
- AIt reduces the priority of microtasks.
- BIt improves the performance of macrotasks.
- CIt allows macrotasks to interleave with microtasks.
- DIt can indefinitely block macrotasks and rendering.