Question 11
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
function showSpinner() { console.log("spinner shown"); }
function render(data) { console.log("render", data); }
setTimeout(showSpinner, 0); // show the spinner "first"
Promise.resolve(["Asha", "Ravi"]).then(render); // cached data, already available
- A setTimeout queues the spinner as a task, which runs after the promise microtask – call showSpinner() synchronously before starting the load Correct
- B render must be async
- C Promise.resolve cannot hold arrays
- D setTimeout delay must be negative
Correct Answer: Option A
Microtasks always beat timer tasks queued in the same turn. Things that must happen first should simply run first, synchronously.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!