Skip to main content

JavaScript Object Spread — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Object Spread 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

    Copy an object

    easy10 min

    Copy an object, change the copy, and show the original is untouched.

  2. 2

    Merge two objects

    easy10 min

    Merge defaults with user settings so the user value wins.

  3. 3

    Update one property

    easy10 min

    Build a new object with active set to true, leaving the original alone.

  4. 4

    Collect the rest

    easy10 min

    Pull out the id and collect the remaining properties, then list their names.

  5. 5

    Add a property while copying

    medium10 min

    Copy an object and add a year in the same expression.

Find the bug(5)

  1. 1

    Fix the shared object

    easy8 min

    Assigning does not copy, so both names point at the same object.

  2. 2

    Fix the merge order

    easy8 min

    The defaults are overwriting the user's choice.

  3. 3

    Fix the original being changed

    easy8 min

    The update should build a new object rather than editing the old one.

  4. 4

    Fix the rest that took everything

    easy8 min

    The id should be pulled out before the rest is collected.

  5. 5

    Fix the property added after the spread

    easy8 min

    The added property is being overwritten by the spread that follows it.

Ready to write the code?

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

Open the workspace