Save a user object and read the name back.
Acceptance criteria
- 1.#out should show Ada.
JavaScript Tutorial · JavaScript Storage & BOM
These 10 tasks go with the JavaScript Storing Objects 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: “JSON.stringify and JSON.parse let you save objects and arrays in storage.” .
1.Save an objectexercise · easy · 10 min
Save a user object and read the name back.
Passes when: #out should show Ada.
2.Save an arrayexercise · easy · 10 min · practice plan
Save a list of tags and count them after loading.
Passes when: #out should show 3.
3.Use a default when nothing is savedexercise · easy · 10 min · practice plan
Fall back to an empty object when the key is missing.
Passes when: #out should show empty.
4.Update a stored objectexercise · easy · 10 min · practice plan
Load, change a property, and save it again.
Passes when: #out should show 2.
5.Recover from bad dataexercise · medium · 10 min · practice plan
Catch a parse failure and fall back to a default.
Passes when: #out should show recovered.
6.Fix the object saved directlybug fix · easy · 8 min
Without stringify the object becomes useless text.
Passes when: #out should show Ada.
7.Fix the missing parsebug fix · easy · 8 min · practice plan
The saved value is still a JSON string until parsed.
Passes when: #out should show 3.
8.Fix JSON.parse called on a missing keybug fix · easy · 8 min · practice plan
JSON.parse(null) quietly parses as the value null instead of an object.
Passes when: #out should show an object.
9.Fix the update never saved backbug fix · easy · 8 min · practice plan
Changing the loaded object does not save it automatically.
Passes when: #out should show 2.
10.Fix the unguarded parse of bad databug fix · easy · 8 min · practice plan
Invalid JSON throws unless it is caught.
Passes when: #out should show recovered.
Between them these tasks cover JSON.stringify, JSON.parse and Error handling.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.