JavaScript Generators Tutorial




Generators in JavaScript Explained

In this tutorial we will look iterators and generators.
– We understand iterators in JavaScript
– Look at a new property called symbol.iterators
– Look at practical use of iterators.

#javaScript #generators #interators
*My Udemy Courses
https://www.udemy.com/js-masterclass/
https://www.udemy.com/course/react-hooks-course/

Follow me for technology updates
* https://facebook.com/techsith
* https://www.facebook.com/groups/techsith
* https://twitter.com/techsith1
* https://www.linkedin.com/groups/13677140/
* https://medium.com/@patelhemil

Help me translate this video.
* https://www.youtube.com/timedtext_cs_panel?c=UCbGZKLIHpox2l0whz6_RYyg&tab=2
Note: use https://translate.google.com/ to translate this video to your language. Let me know once you do that so i can give you credit. Thank you in advance.

Original source


36 responses to “JavaScript Generators Tutorial”

  1. Thank you for your great videos! I would like to see a course from you about design patterns like the observer, singleton patterns and generaly how to structure efficiently and DRY an application by real world examples in react or vanilla js! Greetings from Greece!

  2. I struggle to imagine a real world use case for this. The example you gave at the end could just as easily have been accomplished using async/await which would also be more readable and require fewer lines of code.

  3. Hi Sir,

    For the last example you gave:

    function *generator(){
    yield request('url1');
    yield request('url2');
    }

    This is an easier version for .then callback? Are there any differences between using .then and this method? Thank you for your video!!

  4. Thanks. I wanted to learn Iterators and Generators so I could use Mongorito which makes extensive use of yield statements in its API.

    As an added bonus, I now know how to make my code cleaner with Generators.

  5. I have a doubt in generator example using promise : For this specific example of generator with promise, it seems i can do the such dependent url calls using only promise so that 2nd url call will happen until first finishes and use 1st url data in 2nd, so why do we use generator here ? Please correct me if i am wrong. Thanks for such excellent tutorials !

  6. please put this video after iterators tutorial in advanced javascript tutorial;

    also your channel is awesome, it covers a lot of things I was looking for after going from absolute basics to more advanced things – you explain them really straightforwardly

    iterators and generators might be just what I was looking for – I've got
    reocurring problem with iterate through arrays using for loop, and getting
    expected value after every iteration (not just when value of "i" reaches
    it's limit) – I have to write function for every case.

  7. Thanks! very useful!

    btw, why can I use "let iterator = i.Symbol.iterator()" and have to use let iterator = i[Symbol.iterator]()

    it gives error "VM257:1 Uncaught TypeError: Cannot read property 'iterator' of undefined
    at <anonymous>:1:24"

Leave a Reply