From 21916b17fcbfdae0058e713dd2a1953fd88106f4 Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Mon, 6 Jan 2025 08:55:33 -0800 Subject: [PATCH] Clarify usage of return values in iterator protocol (#37511) * Clarify usage of return values in iterator protocol There's an example with an iterable that returns an iterator that enumerates 1, 2, and returns with `{done: true, value: 3}`, and is evaluated with `const [b, c, d] = obj`. It takes a careful reading to notice that the third value is used only to ensure that the iterator is exhausted and that the value from the iterator return is not bound to `d`. * Update files/en-us/web/javascript/reference/iteration_protocols/index.md --------- Co-authored-by: Joshua Chen --- .../en-us/web/javascript/reference/iteration_protocols/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/files/en-us/web/javascript/reference/iteration_protocols/index.md b/files/en-us/web/javascript/reference/iteration_protocols/index.md index 0eb9fb29805efc9..f9c43484bc9b26c 100644 --- a/files/en-us/web/javascript/reference/iteration_protocols/index.md +++ b/files/en-us/web/javascript/reference/iteration_protocols/index.md @@ -225,6 +225,7 @@ const [b, c, d] = obj; // Returning 3 // Already reached the end (the last call returned `done: true`), // so `return` is not called +console.log([b, c, d]); // [1, 2, undefined]; the value associated with `done: true` is not reachable for (const b of obj) { break;