return
in a generator function is special
the returned value is an IteratorResult (just like any value returned via yield
)
- returns an IteratorResult (an object with the properties
value
anddone
) - the property
value
is the returned value - the property
done
is true - NOTE:
yield
does not returndone=true
butdone=false
! - a missing
return
returns{value: undefined, done: true}
mixing return
and yield
- is possible
- the mix behaves different to two
yield
s - two
yield
s returning values - return a yielded value by "chaining"
return
andyield
Links
Description of the IteratorResult interface.
Describes how a return statement behaves inside a generator.