Practice ยท 2 of 2
Debug: Survive Corrupt Data
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.
Difficulty: beginner
Press Submit to check your solution.
Back to lesson: Practice: State That Survives