ES6 - A beginners guide - Generators Stefan Wright on December 01, 2021 Forewarning: this topic is hard! It's taken me a week to even start to get my head around it. You may have to read this a few times also, I have sp... Read full post Submit Preview Dismiss Collapse Expand Jon Randy ποΈ Jon Randy ποΈ Jon Randy ποΈ Follow π€ Artisanal developer - coding with varying degrees of success since 1983 Location Bangkok πΉπ Joined Jun 1, 2018 • Dec 2 '21 Dropdown menu Copy link Hide Can also be used with for...of: function * numberGenerator() { yield 101 yield 42 yield 33 } for (i of numberGenerator()) { console.log(i) } Enter fullscreen mode Exit fullscreen mode Collapse Expand Stefan Wright Stefan Wright Stefan Wright Follow I'm Stefan, a fullstack developer from Lowestoft, England. Location Lowestoft, Suffolk, United Kingdom Education De Montfort University Pronouns He/Him Work Fullstack Developer @ The Cotswold Company Joined Aug 31, 2021 • Dec 2 '21 Dropdown menu Copy link Hide Of course! I knew there was an asepct I missed out in my write up!! Collapse Expand Jamelle Boose Jamelle Boose Jamelle Boose Follow Joined Aug 24, 2017 • Dec 2 '21 Dropdown menu Copy link Hide I donβt understand why in the first 2 console log examples, value: 3 gets printed twice. Collapse Expand Stefan Wright Stefan Wright Stefan Wright Follow I'm Stefan, a fullstack developer from Lowestoft, England. Location Lowestoft, Suffolk, United Kingdom Education De Montfort University Pronouns He/Him Work Fullstack Developer @ The Cotswold Company Joined Aug 31, 2021 • Dec 2 '21 Dropdown menu Copy link Hide that'll just be a typo :) I'll get that fixed Collapse Expand Jamelle Boose Jamelle Boose Jamelle Boose Follow Joined Aug 24, 2017 • Dec 3 '21 Dropdown menu Copy link Hide You had one job! πππ Jk, I was so confused though. Thanks for confirming! Stefan Wright Stefan Wright Stefan Wright Follow I'm Stefan, a fullstack developer from Lowestoft, England. Location Lowestoft, Suffolk, United Kingdom Education De Montfort University Pronouns He/Him Work Fullstack Developer @ The Cotswold Company Joined Aug 31, 2021 • Dec 3 '21 Dropdown menu Copy link Hide Haha I know, I failed haha Collapse Expand Tobias Franek Tobias Franek Tobias Franek Follow Coder, CTO at bitminds.at Location Austria Education University of Applied Sciences Salzburg - Multimediatechnology Work Developer Joined Mar 24, 2020 • Dec 4 '21 Dropdown menu Copy link Hide Awesome Post! Thank you. Collapse Expand Guillermo Prandi Guillermo Prandi Guillermo Prandi Follow Location Madrid Joined Oct 11, 2019 • Dec 2 '21 Dropdown menu Copy link Hide Example use cases: 1) checksum calculation, 2) deliver content as it arrives (eg. from a server call), 3) break up collections in an efficient way, etc. Collapse Expand Stefan Wright Stefan Wright Stefan Wright Follow I'm Stefan, a fullstack developer from Lowestoft, England. Location Lowestoft, Suffolk, United Kingdom Education De Montfort University Pronouns He/Him Work Fullstack Developer @ The Cotswold Company Joined Aug 31, 2021 • Dec 2 '21 Dropdown menu Copy link Hide Great suggestions, I might have to look into some of them for further examples Collapse Expand ADEOYE ADEFEMI OPEOLUWA ADEOYE ADEFEMI OPEOLUWA ADEOYE ADEFEMI OPEOLUWA Follow JavaScript Developer | Tech enthusiast | Electrical and Electronics Engineering Student | Aspiring MEVN stack developer | Aspiring Rust Developer Email Location Abeokuta, Nigeria Education Undergraduate Joined May 17, 2021 • Dec 1 '21 Dropdown menu Copy link Hide That's a huge one thanks π Collapse Expand Stefan Wright Stefan Wright Stefan Wright Follow I'm Stefan, a fullstack developer from Lowestoft, England. Location Lowestoft, Suffolk, United Kingdom Education De Montfort University Pronouns He/Him Work Fullstack Developer @ The Cotswold Company Joined Aug 31, 2021 • Dec 1 '21 Dropdown menu Copy link Hide This concept is sooo confusing but if its helped someone then I feel that I must have learnt something :) Collapse Expand izaias izaias izaias Follow Eu sou o que sou e Γ© isso que sou! Location Brasil Education 1Β° periodo de analise e desenvolvimento de sistemas Work Devjr Joined Jul 16, 2020 • Dec 2 '21 Dropdown menu Copy link Hide QuΓ£o maravilhoso e aprender e com pessoas criativas o aprendizado fica melhor a cada artigo. nota const nota =()=>{ let number = '1000' console.log(number, ('ParabΓ©ns')) } Code of Conduct • Report abuse
Can also be used with
for...of:Of course! I knew there was an asepct I missed out in my write up!!
I donβt understand why in the first 2 console log examples,
value: 3gets printed twice.that'll just be a typo :) I'll get that fixed
You had one job! πππ Jk, I was so confused though. Thanks for confirming!
Haha I know, I failed haha
Awesome Post! Thank you.
Example use cases: 1) checksum calculation, 2) deliver content as it arrives (eg. from a server call), 3) break up collections in an efficient way, etc.
Great suggestions, I might have to look into some of them for further examples
That's a huge one thanks π
This concept is sooo confusing but if its helped someone then I feel that I must have learnt something :)
QuΓ£o maravilhoso e aprender e com pessoas criativas o aprendizado fica melhor a cada artigo.
nota
const nota =()=>{
let number = '1000'
console.log(number, ('ParabΓ©ns'))
}