LearnFrenzy
Sign in Take a free test

Arrow Functions · Find the Error · Question 3

Error: a generator arrow Answer, explanation & discussion

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

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

main.js
const ids = *() => {
  yield 1;
  yield 2;
};
console.log([...ids()]);
  • A It prints [ 1, 2 ]
  • B SyntaxError: arrow functions cannot be generators – use function* ids() { … } Correct
  • C It prints []
  • D TypeError: ids is not iterable
Correct Answer: Option B

There is no arrow form of a generator. const ids = function* () { yield 1; yield 2; }; works.

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