We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 274929a commit c514225Copy full SHA for c514225
1 file changed
part5 (Functions)/AdvanceFunctions/10_generator-function.js
@@ -0,0 +1,25 @@
1
+/*
2
+INFO: What is a Generator ?
3
+A generator is a special function that can pause and resume its execution using the yield keyword. It automatically creates an iterator.
4
+*/
5
+
6
+function* generatorName() {}
7
8
+- Its returns an iterator
9
+- yield is used to pause and return values one at a time
10
+- Your control flow manually with .next()
11
12
13
+// Example
14
+function* nameGenerator() {
15
+ yield "rafay";
16
+ yield "ali";
17
+ yield "john";
18
+}
19
20
+const gen = nameGenerator();
21
22
+console.log(gen.next()); // {value: "rafay", done: false}
23
+console.log(gen.next()); // {value: "ali", done: false}
24
+console.log(gen.next()); // {value: "john", done: false}
25
+console.log(gen.next()); // {value: "undefined", done true}
0 commit comments