In JavaScript generator functions, each yield expression requires two next() calls to complete: the first call pauses execution and returns the yielded value, while the second call resumes execution and evaluates the yield expression to a value (which can be passed as an argument or defaults to undefined), allowing the generator to continue running until completion.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
yield expression of generator function in JavaScript explained
Added:Every yield expression inside a generator function requires two next calls. In this example, I have a generator function called test. And I'm calling test to get the iterator object, and I'm calling iterator.next here.
So, the execution of the function starts, and at line number five, since we have a yield expression, the execution pauses, and it returns an object having value three and done false.
So, you can see that one is printed, two is printed, then we have an object of value three and done false. Now, the execution is paused at line number five.
On the next next call, the execution resumes from this stage, which means if you call the next again, this paused yield expression will be evaluated to a value, and that value will be stored to this variable, and that variable will be printed here.
Now, on this next call, we can pass a value, and that value will be the evaluated value of the paused yield expression.
Now, if in this case, if you don't pass any value, then this paused yield expression will be evaluated to undefined, and we will get undefined printed here. So, let's check that.
You can see that undefined is printed.
Since there is no more yield expressions, it returns an object with value undefined and done true.
Now, here in this case, let me pass the value 10.
Okay? So, from this first next call, the execution paused at this stage, and on the second next call, the yield expression evaluates to the value that we passed, which is 10. So, 10 will be the evaluated value, and let's check that.
You can see that 10 is printed. So, this is how yield expression works.
Related Videos
LBF101 Creating an XML Changelog
liquibase7511
3K views•2026-06-15
Alta Labs Cloud Dashboard Real time Network & Xnet Insights!
ShinyTechThings
158 views•2026-06-17
Wait... Group Policy Not Applying? Check This First!
keeplearning_iT
144 views•2026-06-15
Leetcode Weekly Contest 506 | Life's boring these days
Pudeesht
2K views•2026-06-14
microJAM: MAKING A MICRO GAME FOR A GAME JAM IN CLOJURESCRIPT AND TOTALLY NOT C
janetacarr
156 views•2026-06-18
Partitioning vs Bucketing vs Clustering: How to Make Queries 100x Faster
thedataandaiguy
194 views•2026-06-16
Design Claude Code Like a Senior Engineer
hayk.simonyan
344 views•2026-06-19
Linus Torvalds: AI Won’t Replace Understanding Code
SavvyNik
140 views•2026-06-19











