What is the yield Keyword in JavaScript? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 4 Likes 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 A abhishek7 Follow 4 Improve A abhishek7 Follow 4 Improve Article Tags : JavaScript Web Technologies Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like