Skip to main content

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

Back to lesson: Practice: State That Survives