JSFiddle - React, Tailwind, and code Playground

by Sandeep Agrawal

HTML

<pre id="output"></pre>

JavaScript

function * generator() {
    console.log('First execution.');
    yield 'Yield First execution, saved the state and exit';
    return 'generator execution ends here due to return and it will not execute any code after this line.';  
    yield 'Yield second execution, saved the state and exit';
}

const generatorObj = generator();
setTimeout(() => document.getElementById('output').innerHTML += "\n" + JSON.stringify(generatorObj.next()), 1000);
setTimeout(() => document.getElementById('output').innerHTML += "\n" + JSON.stringify(generatorObj.next()), 3000);
setTimeout(() => document.getElementById('output').innerHTML += "\n" + JSON.stringify(generatorObj.next()), 5000);