LearnFrenzy
Sign in Take a free test

Event Loop · Find the Error · Question 11

Bug: the spinner appears after the data Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?

main.js
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links