Skip to main content

JavaScript Destructuring — exercises and bug fixes

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

    Destructure an object

    easy10 min

    Pull the name and age out of a person object into their own variables.

  2. 2

    Destructure an array

    easy10 min

    Pull the first two colours out of an array.

  3. 3

    Skip an element

    easy10 min

    Use a gap to take only the third colour.

  4. 4

    Rename while destructuring

    easy10 min

    Pull out name but call the variable fullName.

  5. 5

    Use a default value

    medium10 min

    Give size a default because the object does not have one.

Find the bug(5)

  1. 1

    Fix the brackets used for an object

    easy8 min

    Objects destructure by name with braces, so position gives the wrong value.

  2. 2

    Fix the name that does not match

    easy8 min

    Object destructuring matches by property name.

  3. 3

    Fix the default that never applies

    easy8 min

    A default only fills in for undefined, and the value was set to null.

  4. 4

    Fix the missing gap

    easy8 min

    Without the gap the first element is taken instead of the third.

  5. 5

    Fix the parameter not destructured

    easy8 min

    The function receives an object but reads it as if it were a plain value.

Ready to write the code?

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

Open the workspace