Generator Functions in JavaScript - 4 ways to use it with examples

Опубликовано: 08 Май 2020
на канале: Developer Tharun
3,836
58

Learn Complete JavaScript in 7 hours: https://www.udemy.com/course/javascri...



------



What are Generator Functions?



Ever imagined what would happen if a function had an infinite input or output to deal with? That is exactly what you can handle with Generator functions.A Generator function returns us an iterator, which can be used to stop the function in the middle, do something, and then resume it whenever. A normal function starts executing and returns when the function completes, but a Generator function can be stopped any number of times and resumed later.


Recap: What is a Function?



A function is a block of code that can be called any number of times to get the functionality done and sometimes the result returned.