Copy an object, change the copy, and show the original is untouched.
Acceptance criteria
- 1.#out should show Ada.
JavaScript Tutorial · JavaScript Objects
These 10 tasks go with the JavaScript Object Spread chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “The JavaScript spread operator copies the properties of one object into another.” .
1.Copy an objectexercise · easy · 10 min
Copy an object, change the copy, and show the original is untouched.
Passes when: #out should show Ada.
2.Merge two objectsexercise · easy · 10 min · practice plan
Merge defaults with user settings so the user value wins.
Passes when: #out should show dark medium.
3.Update one propertyexercise · easy · 10 min · practice plan
Build a new object with active set to true, leaving the original alone.
Passes when: #out should show false then true.
4.Collect the restexercise · easy · 10 min · practice plan
Pull out the id and collect the remaining properties, then list their names.
Passes when: #out should show name,city.
5.Add a property while copyingexercise · medium · 10 min · practice plan
Copy an object and add a year in the same expression.
Passes when: #out should show Toyota 2021.
6.Fix the shared objectbug fix · easy · 8 min
Assigning does not copy, so both names point at the same object.
Passes when: #out should show Ada.
7.Fix the merge orderbug fix · easy · 8 min · practice plan
The defaults are overwriting the user's choice.
Passes when: #out should show dark.
8.Fix the original being changedbug fix · easy · 8 min · practice plan
The update should build a new object rather than editing the old one.
Passes when: #out should show false then true.
9.Fix the rest that took everythingbug fix · easy · 8 min · practice plan
The id should be pulled out before the rest is collected.
Passes when: #out should show 2 left.
10.Fix the property added after the spreadbug fix · easy · 8 min · practice plan
The added property is being overwritten by the spread that follows it.
Passes when: #out should show Toyota 2021.
Between them these tasks cover Spread, Rest properties and Merging objects.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.