Get the App
SLTechnology News&Howtos  ›  Development  › 

Introduction and usage of yield keyword in javascript

Shulou Source: shulou.com Published: 2022-06-03 17:30:56 10月27日 Update

This article mainly explains the "introduction and use of the yield keyword in javascript". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "the introduction and use of the yield keyword in javascript".

1. The yield keyword can only be used in the generator function, which means to pause the execution of the internal code of the function and return the current iteration data.

2. If there is no next yield,next, the done of the returned object will be placed as true.

After the yield keyword, the result of the expression returns the value as next.

Example

Def foo (): print ("starting...") While True: res = yield 4 print ("res:", res) g = foo () print (next (g)) print ("*" * 20) print (next (g)) Thank you for your reading. This is the content of "introduction and use of the yield keyword in javascript". After studying this article, I believe you have a deeper understanding of the introduction and use of the yield keyword in javascript. The specific use situation still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Keywords keywords usage methods learning content functions code examples objects that is ideas situations data articles methods more generators knowledge knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Xiaomi Shulou Technology Redmi