DEV Community

Cover image for Let's Learn Generators in JavaScript πŸš€

Let's Learn Generators in JavaScript πŸš€

Jagroop Singh on November 29, 2024

Hey, JavaScript enthusiasts! πŸ‘‹ Are you ready to supercharge your coding skills? Today, we’re diving into Generators β€” a special kind of function in...
Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Damn, these are so powerful, I can think of n number of ways to use this like a progress bar and infinite scroll block with dynamic data fetching. thanks @jagroop2001

Collapse
 
jagroop2001 profile image
Jagroop Singh

You're welcome! @thesohailjafri

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

learning new things every day from you, keep it up bro <3

Collapse
 
itamartati profile image
Itamar Tati

What's a real world use case for Generators

Collapse
 
pengeszikra profile image
Peter Vivo

redux-saga is great generator based library extending by redux with async state handling for complex busines logic.

I write a POC program - long time ago, when generator released in JS :
poker game poc, with generators and regexp
The main game loop was solved with generator.

Collapse
 
jagroop2001 profile image
Jagroop Singh

Great example @pengeszikra

Collapse
 
philip_zhang_854092d88473 profile image
Philip

This is an excellent and engaging introduction to JavaScript Generators! πŸš€ Generators are powerful for tasks like lazy evaluation and asynchronous flow, and with EchoAPI, you can efficiently test and mock APIs that use generator functions, simplifying your development and debugging process.

Collapse
 
jagroop2001 profile image
Jagroop Singh

Thanks for the insightful take!

Collapse
 
slobodan4nista profile image
Slobi

Level up content!

Collapse
 
jagroop2001 profile image
Jagroop Singh

Absolutely! Let's keep pushing boundaries and discovering new possibilities! πŸ’‘πŸš€

Collapse
 
pinwheeler profile image
Anthony Dreessen

I forgot I was scared of the yield sign. You completely clarified things. You should be proud of you. I'm proud of you!

Collapse
 
jagroop2001 profile image
Jagroop Singh

Thanks @pinwheeler

Collapse
 
dan_maroff profile image
Dan Maroff

Fantastic! Didn’t know this functionality existed in JavaScript πŸ˜€

Collapse
 
jagroop2001 profile image
Jagroop Singh

That's awesome! JavaScript keeps surprising us with its hidden gems! πŸš€

Collapse
 
momodev profile image
Santiago G. MarΓ­n

Great article. First time I've seen actually useful examples for generators. Thanks!

Collapse
 
jagroop2001 profile image
Jagroop Singh

Thanks @momodev

Collapse
 
gauravsinghbisht profile image
Gaurav Singh Bisht

Great tutorial. It is an awesome feature

Collapse
 
jagroop2001 profile image
Jagroop Singh
Collapse
 
skhmt profile image
Mike • Edited

To be fair it's closer to a 1.7976931348623157e+308 series number generator than infinity, although any more than that JS will just return Infinity so maybe it is an infinite number generator

Collapse
 
starboysharma profile image
Pankaj Sharma

So easy to understand and I like the idea of using generators for lazy load data in chunks.