Local storage allows developers to store and retrieve data in the browser. The data stored in local storage will not expire. This means the data will persist even if the tab or the browser window is closed.
Local storage is a form of web storage that stores data for a long time. This could be a day, a week, or even a year. This depends upon the developer’s preference. It is important to note that local storage only stores strings so, if you wish to store objects, lists, or arrays, you must convert them into a string using JSON.stringify().
https://www.section.io/engineering-education/how-to-use-localstorage-with-javascript/
You should only use local storage when storing insensitive information. This is because third-party individuals can easily access the information. Local storage can help in storing temporary data before it is pushed to the server. It is important to clear the local storage once this operation is completed.
Passwords and personal information should not be stored in local storage. Also it is wise to keep anything out that needs to be synchronized to run.
The primary methods when using local storage are key(), setItem(), removeItem(), getItem(), and clear().
key() This method is used to retrieve a value/string from a specific location. The index can be passed into the key() function as a parameter. The key() can also be used in a loop statement to retrieve all the items in the local storage.
setItem() This function is used to store items in local storage. As mentioned before, we must stringify objects before we store them in the local storage.
getItem() This function is used to access or retrieve the data in the local storage. The method takes in a key as a parameter. It then extracts the required value from the localSstorage.
removeItem() This method is used to delete an item from local storage. The removeItem() method requires a key as a parameter.
clear() This method is used to clear all values stored in local storage. It does not require any parameters.
https://www.section.io/engineering-education/how-to-use-localstorage-with-javascript/