Practice · 2 of 2
Debug: Survive Corrupt Data
CHALLENGE
Difficulty: beginner+25 XP
This loader crashes when the stored value isn't valid JSON. Add a try/catch around the parse: on failure, return the default { theme: "light" }. Test by storing garbage ("not-json{{") and loading — it must return the default instead of throwing.
Rules:
- try/catch around JSON.parse.
- The catch returns the default.
Press Submit to check your solution.
Back to lesson: Practice: State That Survives