How do you create a generator function in JavaScript?
a) By using the
function*
syntaxb) By using
function generator()
c) By using the
new Generator()
keywordd) By using the
Promise()
constructorAnswer:
a) By using the
function*
syntaxExplanation:
A generator function in JavaScript is defined using the function*
syntax. Generator functions return a generator object that can be used to control the function’s execution using the yield
keyword to pause and resume execution.