Search⌘ K
AI Features

Removing Noise With Yield

Explore how to use the yield keyword in JavaScript to create efficient iterators. Learn how yield pauses and resumes function execution, making iterator code more fluent and less nested for better control and clarity.

Introduction

Let’s put the role of the iterator method, introduced in the previous lesson into words. As the caller iterated over the object, the iterator yielded the next value. To achieve that, we wrote quite a bit of code. We can get rid of most of the extraneous code using the special yield keyword.

Using yield

The ...