DEV Community

Cover image for Quick tip about function vs function*
Benjamin🦸‍♂️Auzanneau™
Benjamin🦸‍♂️Auzanneau™

Posted on • Edited on

2 3

Quick tip about function vs function*

What is function * ?

It's generator function which returns a Generator object.
Generators are intricately linked with iterators.

But what is a generator function ?

It's a function that can stop midway and then continue from where it stopped !

function * generatorExample() {
  let counter = 0;
  yield `First step ! ${counter}`;
  counter++;
  yield `Second step ! ${counter}`;
  counter++;
  console.log('No yield, the function is done');
}

const generator = generatorExample();
console.log(generator.next().value); // First step ! 1
console.log(generator.next().value); // Second step ! 2
console.log(generator.next().value); // No yield, the function is done
Enter fullscreen mode Exit fullscreen mode

The Generator object offers a next() function that you can call to go further into the next step of the generator.

You can check MDN for more information.

That's it, make good use of it !


I'm not a native English speaker so, thanks in advance if you want to improve my article with correct syntax/grammar/sentences.

I can accept all kind remarks :)

Cover by Wolfgang Rottmann on Unsplash

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (0)

Jetbrains image

Is Your CI/CD Server a Prime Target for Attack?

57% of organizations have suffered from a security incident related to DevOps toolchain exposures. It makes sense—CI/CD servers have access to source code, a highly valuable asset. Is yours secure? Check out nine practical tips to protect your CI/CD.

Learn more

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay