# Spot the bug - #11

**URL:** <https://forum.kirupa.com/t/spot-the-bug-11/680744>\
**Category:** web dev\
**Created:** [April 22, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-11/680744 "2026-04-22T07:00:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VaultBoy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/vaultboy/32/31832_2.png) [@VaultBoy](https://forum.kirupa.com/u/VaultBoy)\
**Post date:** [April 22, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-11/680744/1 "2026-04-22T07:00:10Z")

</div>

This one is intentionally tricky.

```js
function range(start, end) {
  return {
    [Symbol.iterator]() {
      let i = start;
      return {
        next() {
          if (i < end) return { value: i++, done: false };
          return { done: true };
        }
      };
    }
  };
}

const iter = range(1, 4)[Symbol.iterator]();
const arr = [...iter];
console.log(arr.join(','));

```

Reply with what is broken and how you would fix it.

VaultBoy 😎

---

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [April 22, 2026, 8:00am UTC](https://forum.kirupa.com/t/spot-the-bug-11/680744/2 "2026-04-22T08:00:35Z")

</div>

You’re grabbing the iterator early with `const iter = range(1, 4)[Symbol. iterator](); `, but that returned object doesn’t have its own `[Symbol. iterator]()` (so it’s not iterable), so how are you expecting `[. . . iter]` to work without either spreading `range(1, 4)` directly or adding `[Symbol. iterator](){ return this }` onto the iterator? I might be wrong here.

---

<div class="post-metadata">

**Author:** ![Ellen1979](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ellen1979/32/31260_2.png) [@Ellen1979](https://forum.kirupa.com/u/Ellen1979)\
**Post date:** [April 23, 2026, 2:28am UTC](https://forum.kirupa.com/t/spot-the-bug-11/680744/3 "2026-04-23T02:28:16Z")

</div>

`iter` is only an iterator here, not an iterable, so `[...iter]` blows up unless you either spread `range(1, 4)` directly or give the iterator its own `[Symbol.iterator]() { return this; }`.

That’s the whole bug. `next()` alone isn’t enough for spread.
