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
Destructure an object
easy10 minPull the name and age out of a person object into their own variables.
- 2
Destructure an array
easy10 minPull the first two colours out of an array.
- 3
Skip an element
easy10 minUse a gap to take only the third colour.
- 4
Rename while destructuring
easy10 minPull out name but call the variable fullName.
- 5
Use a default value
medium10 minGive size a default because the object does not have one.
Find the bug(5)
- 1
Fix the brackets used for an object
easy8 minObjects destructure by name with braces, so position gives the wrong value.
- 2
Fix the name that does not match
easy8 minObject destructuring matches by property name.
- 3
Fix the default that never applies
easy8 minA default only fills in for undefined, and the value was set to null.
- 4
Fix the missing gap
easy8 minWithout the gap the first element is taken instead of the third.
- 5
Fix the parameter not destructured
easy8 minThe 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