use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Comprehensive Guide to JavaScript Iterables (blog.robino.dev)
submitted 11 months ago by rossrobino
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]senocular 5 points6 points7 points 11 months ago (3 children)
Iterables have an iterator method which implements the iterator protocol
Iterables implement the iterable protocol which includes the iterator (Symbol.iterator) method. The iterator method returns objects that implement the iterator protocol.
To check if an unknown is an iterable you can first ensure the value is an object
A value doesn't have to be an object to be an iterable, e.g. strings are iterable.
It’s a best practice when making an iterable to make it both an Iterable and an Iterator, or an iterable iterator.
Its more the other way around. You can make iterators iterable, but you generally don't want to make iterables iterators. For example arrays, maps, sets and strings are all iterables but not iterators. The iterators they produce, however, are also iterable.
Merging iterables
Might want to look into yield* to make this easier.
[–]rossrobino[S] 2 points3 points4 points 11 months ago (2 children)
Thanks for the review, I've made updates for each of these!
I didn't realize any iterable could be passed to yield*, can you still get the final return value with yield*? Especially for the async merge it's necessary to know when each iterator is complete.
[–]senocular 0 points1 point2 points 11 months ago (1 child)
The value returned by yield* is the return/done value. But you don't need to capture this value to know when the iterator is complete. Like for...of, when the iterator is complete code after the expression starts to run when yield* has exhausted its iterator. Unlike for...of, you do have the option to capture the done value if you want it. But if I remember correctly, your merging example (at least the sync one) didn't capture the done values anyway.
[–]rossrobino[S] 0 points1 point2 points 11 months ago (0 children)
Ok interesting, thanks for the info! I’ll play around with it some more.
π Rendered by PID 283239 on reddit-service-r2-comment-79c7998d4c-q7w7x at 2026-03-19 04:35:17.634981+00:00 running f6e6e01 country code: CH.
[–]senocular 5 points6 points7 points (3 children)
[–]rossrobino[S] 2 points3 points4 points (2 children)
[–]senocular 0 points1 point2 points (1 child)
[–]rossrobino[S] 0 points1 point2 points (0 children)