Question 3
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
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!