Hint
next(val) injects val as the resolved value of the previous yield. The first next() argument is always ignored.
function* dialog() {
const name = yield 'What is your name?';
yield 'Hello, ' + name;
}
const g = dialog();
console.log(g.next().value);
console.log(g.next('Alice').value);What is your name? Hello, Alice
Explanation: First next() starts the generator, returns "What is your name?". next("Alice") resumes — "Alice" becomes the result of the yield expression.
Key Insight: next(val) injects val as the resolved value of the previous yield. The first next() argument is always ignored.