

InterviewSolution
Saved Bookmarks
1. |
What is a generator in JavaScript? |
Answer» <html><body><p>With the <a href="https://interviewquestions.tuteehub.com/tag/launch-246614" style="font-weight:bold;" target="_blank" title="Click to know more about LAUNCH">LAUNCH</a> of ES6, a new way of working with functions and iterators came into work. These are called generators. A generator is nothing but a function that can <a href="https://interviewquestions.tuteehub.com/tag/stop-1228105" style="font-weight:bold;" target="_blank" title="Click to know more about STOP">STOP</a> at the point of time when the user commands it to do so and then continue working just from the point where it stopped. In other words, a generator has <a href="https://interviewquestions.tuteehub.com/tag/properties-11511" style="font-weight:bold;" target="_blank" title="Click to know more about PROPERTIES">PROPERTIES</a> of a function but also works as an iterator. It does not work like other lines of code which need to be completed for execution.</p><p>Generators work on a run-to-completion model which makes it easier for the developers to compile a <a href="https://interviewquestions.tuteehub.com/tag/program-246414" style="font-weight:bold;" target="_blank" title="Click to know more about PROGRAM">PROGRAM</a>. Generators can also be defined as a special class of functions that work to simplify the task of coding iterators in a program. It produces a sequence of results rather than producing a single value. It enables the developer to generate a series of values at a time.</p><p><em>This is very important<strong> javascript ES6 Interview </strong><strong>Questions</strong>.</em></p></body></html> | |