###### Table of Contents
- [[#About]]
- [[]]
- [[]]
- [[]]
## About
Generators are functions that can be paused and resumed as many times as desired. At each pause it can yield a value back, much like it would `return`, except it's just paused (you can resume it then yield another value back)
```js
function* g1() {
console.log('Hello');
yield 'Yield 1 Ran...';
console.log('World');
yield 'Yield 2 Ran...';
}
// nothing will happen here
g1();
// must assign to a variable
let g = g1();
console.log(g.next());
//➞ 'Hello'
//➞ { value: 'Yield 1 Ran...', done: false }
// or, if the above line was console.log(g.next().value)
//➞ 'Hello' 'Yield 1 Ran..'
// at this point function execution is paused. to get it to resume run next() again
console.log(g.next())
//➞ 'World'
//➞ { value: 'Yield 2 Ran..', done: false }
// for done not to be false the function needs to return a value and then run next again
function* g1() {
console.log('Hello');
yield 'Yield 1 Ran...';
console.log('World');
yield 'Yield 2 Ran...';
return 'Returned...';
}
console.log(g.next());
//➞ { value: 'Returned...', done: true }
```
You can also use a generator function as an iterator:
```js
for(let value of g) {
console.log(value);
}
//➞ 'Y'
```
#### More info
[Some website](https://test.com)
___
**Tags**: