cf.completefrontend

Predict the outputMedium

What does this generator log when you pass values into next()?

What does this log?
function* calculator() {
  const x = yield "first";
  console.log("x is", x);
  const y = yield x * 10;
  console.log("y is", y);
  return x + y;
}
 
const it = calculator();
console.log(it.next("ignored"));
console.log(it.next(2));
console.log(it.next(3));
console.log(it.next(4));

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…