yield keyword is used to resume or pause a generator function asynchronously. A generator function is just like a normal function but the difference is that whenever the function is returning any value, it does it with the help of ‘yield’ keyword instead of return it. Yield can’t be called from nested functions or from callbacks.
The yield expression returns an object with two properties, “value” which is the actual value and “done” which is a boolean value, it returns true when generator function is full completed else it returns false.
If we pause the yield expression, the generator function will also get paused and resumes only when we call the next() method. When the next() method is encountered the function keeps on working until it faces another yield or returns expression.
- Golang program that uses fallthrough keyword
- How to implement is functionality without using is keyword in C#
- Final keyword in PHP
- Global keyword in Python
- Invoking an overloaded constructor using this keyword in C#
- Throw Keyword in Scala
- CSS | currentcolor keyword
- PHP | var keyword
- CSS | revert keyword
- ES6 | Void Keyword
- Difference between revert and unset keyword in CSS
- CSS | unset keyword
- Difference between private keyword and private fields in TypeScript
- Range Keyword in Golang
- Golang program that uses defer keyword
- How to instantiate Struct using new keyword in Golang?
- $this keyword in PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.