What is the yield Keyword in JavaScript? Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The yield keyword in JavaScript is used to pause and resume a generator function asynchronously. A generator function works similarly to a normal function, but instead of returning values with return, it uses yield. This allows for the function's execution to be paused and resumed at specific points. The yield expression returns an object containing two properties: value, which holds the yielded value, and done, a boolean that indicates whether the generator function has been completed (true) or is still in progress (false). Pausing a yield pauses the generator, and it resumes when the next() method is called. The function continues executing until it encounters another yield or return statement.Example 1: This example shows the usage of yield keyword in JavaScript. javascript function* showPrices(i) { while (i < 3) { yield i++; } } // Creating an object for our function showPrices const gfg = showPrices(0); // Return 0 because 0 value is passed to the // showPrices yield expression console.log(gfg.next().value); // return 1 console.log(gfg.next().value); //return 2 console.log(gfg.next().value); Output0 1 2 Example 2: This example shows the usage of yield keyword in JavaScript. javascript function* geeksforGeeks() { // Expression paused here and return value // is undefined as nothing is declared yield; // Wait for next() to finish gfg(yield "Welcome to GFG"); } function gfg(x) { console.log("Hello World ", x) } let generator = geeksforGeeks(); //return undefined console.log(generator.next()); //return Welcome to GFG console.log(generator.next()); Output{ value: 'Welcome to GFG', done: false } Hello World undefined { value: undefined, done: true } Comment More infoAdvertise with us Next Article What is An Event Loop in JavaScript? A abhishek7 Follow Improve Article Tags : JavaScript Web Technologies Similar Reads What is the difference between await and yield keywords in JavaScript ? In this article, we will see how Await keyword is different from Yield keywords. Generator Functions: Functions that can return multiple values at different time interval as per the user demands, and can manage its internal state are generator functions. A function becomes a Generator function if it 3 min read What is $ {} in JavaScript ? In JavaScript, the ${} syntax is used within template literals, also known as template strings. Template literals, introduced in ECMAScript 6 (ES6), provide a convenient way to create strings with embedded expressions. They are enclosed within backticks (`) instead of single quotes ('') or double qu 2 min read JavaScript yield Operator The yield operator in JavaScript is used to hand over control of a generator function to another generator function or iterable object. It's handy for yielding values from an inner generator or iterable object within an outer generator function. This operator finds application in tasks like working 3 min read What is JavaScript? JavaScript is a powerful and flexible programming language for the web that is widely used to make websites interactive and dynamic. JavaScript can also able to change or update HTML and CSS dynamically. JavaScript can also run on servers using tools like Node.js, allowing developers to build entire 6 min read What is An Event Loop in JavaScript? The event loop is an important concept in JavaScript that enables asynchronous programming by handling tasks efficiently. Since JavaScript is single-threaded, it uses the event loop to manage the execution of multiple tasks without blocking the main thread.JavaScriptconsole.log("Start"); setTimeout( 4 min read What does '...' mean in JavaScript? The '...' (or 3 dot symbol) in JavaScript is known as the Spread operator or Rest operator based on the usage. This syntax is used to expand the iterable into individual elements such as arrays, objects, etc.Syntax for Spread Operatorcosnt a1 = [ 10, 20, 30, 40 ];const a2 = [ ...a1, 50]; // Extracti 4 min read Like