State, JSON, and Local Storage
Model interface state, serialize it safely, and restore device-local preferences.
Lesson introduction
Application state is the data needed to render the current interface. Keep one clear state value, derive the view from it, and treat storage as an external boundary. localStorage stores strings, so JSON data must be parsed, validated, and given a safe fallback.
Where this fits
This lesson builds one part of the path from language fundamentals to complete browser applications.
What you will build
Save and restore one display preference with a validated fallback.
You will first study the underlying rule, then trace worked code, repair a mistake, and create an independent solution.