Dev HelpersOpen library
← Back

Send a value into a generator

Send a value into a generator in JavaScript.

Open this example in the interactive library

Source code

function* prompt() {
  const name = yield "Name?";
  return "Hello " + name;
}
const conversation = prompt();
console.log(conversation.next().value, conversation.next("Ada").value);

Sample output

Name? Hello Ada