Image for post
Image for post
Photo by Frederick Tubiermont on Unsplash

GENERATOR FUNCTIONS

A generator is a function that can stop midway, then continue execution from the stopping point. Generator functions behave like an iterator. They are declared almost identically to regular functions with just one exception — the asterisks *. To declare generator functions, we need the function syntax. This means that we can’t declare them using arrow function syntax.

You can do:

function* generator1() {
//code here
}
const generator2 = function *() {
//code here
}

But, if you try to do this, you’ll get a syntax error:

const generator3 = *() => {
//code here
}

Which is sad because arrow functions are sexy. 😢
Petition to allow arrow syntax for generator functions! …

About

Bashiru Ismail Babatunde

In the midst of winter, I found that there was within me an invincible summer — Albert Camus | Full Stack Web Developer/Creative Designer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store