How do you create a generator function in JavaScript?

How do you create a generator function in JavaScript?

a) By using the function* syntax
b) By using function generator()
c) By using the new Generator() keyword
d) By using the Promise() constructor

Answer:

a) By using the function* syntax

Explanation:

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.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top