Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
generators
function
method

What are JavaScript generators?

Educative Answers Team

Generators are functions that can pause execution midway through and then continue from where they stopped.

A standard function in JavaScript runs until it ​returns or executes its last line of code. Invoking the function again causes it to begin execution from the start. In contrast, a Generator can stop midway and yield a return value. Invoking the Generator again resumes the execution from where it last left off.

The following illustration highlights this difference: