๐ฆyield
JS โฉ objects โฉ built-in โฉ Generator โฉ generator function โฉ yield
JS โฉ statement โฉ control flow โฉ jump โฉ yield
(used only in generator functions) to produce the next value without returning.
yield and yield* operator can only be used within generator functionsโ๏ธ
replit๏ผyield must be in generator functions
// this seems like a generator function, but there's a catch ...
function* sequence(...iterables) {
// --------------------------------------------------------------
// โญ `yield/yield*` only available within generator functionsโ
// --------------------------------------------------------------
// โ but this `yield*` is within an "arrow function"โ
//
// โญโโโ ๐ธ arrow function โโโโฎ
iterables.forEach( iterable => yield* iterable );
// ^^^^^^
// โ ReferenceError: yield is not defined
}
Last updated
Was this helpful?