The return() method returns the given value and finishes the generator.




The value to return.

Return value

The value that is given as an argument.


Using return()

The following example shows a simple generator and the return method.

function* gen() { 
  yield 1;
  yield 2;
  yield 3;

var g = gen();;        // { value: 1, done: false }
g.return('foo'); // { value: "foo", done: true };        // { value: undefined, done: true }


if done is true,  return(value) as same as next(),value is undefined. (It does not look like this in Chrome; version: 54)

function* gen() {yield 1;}
var g = gen();
console.log(; //{ value: 1, done: false }
console.log(; //{ value: undefined, done: true }
console.log(g.return(1)); //{ value: undefined, done: true }


Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Generator.prototype.return' in that specification.
Standard Initial definition.
ECMAScript 2017 Draft (ECMA-262)
The definition of 'Generator.prototype.return' in that specification.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 50 13 38 (38) No support 37 10
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support 50 38.0 (38) ? ? 10

See also

Document Tags and Contributors

 Contributors to this page: nmve, kdex,, David_Gilbertson, eduardoboucas, panhezeng, fscholz
 Last updated by: nmve,