LearnFrenzy
Sign in Take a free test

Event Loop · Find the Error · Question 7

Error: a failure inside queueMicrotask Answer, explanation & discussion

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

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
const raw = "";                              // the cache file was empty
queueMicrotask(() => {
  const settings = JSON.parse(raw);
  console.log("theme:", settings.theme);
});
console.log("app ready");
  • A It prints theme: undefined
  • B It prints app ready only
  • C The script is rejected before it runs
  • D After "app ready", JSON.parse("") throws a SyntaxError inside the microtask, which nothing catches Correct
Correct Answer: Option D

The code is valid; the parse fails at run time. Errors thrown in queueMicrotask callbacks are reported as uncaught – guard the parse with try/catch.

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