reading-notes

Local Storage and How To Use It On Websites

1. Why would a developer use local storage for a web application?

Developers use local storage primarily to add “state” to the web, overcoming the fact that HTTP is a stateless protocol where closing an application typically resets its data. Key reasons include:

2. What information should not be stored in local storage?

3. Local storage data types and conversion

Local storage is restricted in that it can only store strings. If you attempt to store an object directly, it will be saved incorrectly as “[object Object]” rather than the actual data.

To store complex data like objects or arrays, you must convert them into a string using the native JSON.stringify() method before saving them. When you need to retrieve and use that data again, you use JSON.parse() to convert the string back into its original object format.