๐Ÿ“ฆyield

(expression)

(used only in generator functions) to produce the next value without returning.

yield and yield* operator can only be used within 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