Opens in a new tab
A picture of Jeff Brigman
I CODE TODAY FOR
A BETTER TOMORROW

Glossary Term

Generator.prototype.return()

2 tags 1 category

The return() method of Generator instances acts as if a return statement is inserted in the generator’s body at the current suspended position, which finishes the generator and allows the generator to perform any cleanup tasks when combined with a try…finally block.

The return() method, when called, can be seen as if a return value; statement is inserted in the generator’s body at the current suspended position, where value is the value passed to the return() method. Therefore, in a typical flow, calling return(value) will return { done: true, value: value }. However, if the yield expression is wrapped in a try…finally block, the control flow doesn’t exit the function body, but proceeds to the finally block instead. In this case, the value returned may be different, and done may even be false, if there are more yield expressions within the finally block.

Syntax example: generatorInstance.return()

Term Connections

Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.

Loading term connections…