Question 3
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
function* ticker() {
setTimeout(() => {
yield "tick";
}, 100);
}
- A It yields "tick" after 100 ms
- B SyntaxError: yield is only allowed directly in the generator body, not in a nested arrow function Correct
- C It yields undefined
- D TypeError when ticker() is called
Correct Answer: Option B
A generator cannot yield from a callback that runs later. Use an async generator that awaits a timer promise and then yields.
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!