Skip to main content

JavaScript Iterables — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Iterables lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Confirm an array is iterable

    easy10 min

    Report the type of an array's Symbol.iterator method.

  2. 2

    Loop over a Set

    easy10 min

    Use for of to collect values from a Set.

  3. 3

    Catch a non-iterable loop

    easy10 min

    Catch the error from looping over a plain object.

  4. 4

    Spread a string

    easy10 min

    Spread a string into an array of its characters.

  5. 5

    Tell iterable spread from object spread

    medium10 min

    Show both kinds of spread working on their own kind of value.

Find the bug(5)

  1. 1

    Fix for of used on a plain object

    easy8 min

    Plain objects are not iterable.

  2. 2

    Fix the spread of a plain object as a list

    easy8 min

    Spreading an object into an array position needs it to be iterable.

  3. 3

    Fix the Map assumed non-iterable

    easy8 min

    A Map is iterable, yielding key-value pairs.

  4. 4

    Fix the string spread miscounted

    easy8 min

    Spreading a string gives one entry per character, not per byte pair blindly assumed.

  5. 5

    Fix destructuring used on a non-iterable

    easy8 min

    Array destructuring needs an iterable on the right side.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace