LearnFrenzy
Sign in Take a free test

Event Loop · Find the Error · Question 2

Error: an "async" arrow that is not async Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

JavaScript refuses to run the code below. Which statement correctly describes the problem?

main.js
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
queueMicrotask(async => {
  await wait(10);
  console.log("done");
});
  • A It logs done after 10 ms
  • B SyntaxError: async => { … } is a normal arrow with a parameter named async, so await inside it is invalid – write async () => { … } Correct
  • C queueMicrotask cannot take arrow functions
  • D TypeError at run time
Correct Answer: Option B

async is only a keyword when it comes before a parameter list or function; on its own it is a valid identifier.

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