Before i go into what local storage is, let me quickly give a simple background.
The Web storage API provides mechanisms by which browsers can securely store key/value pairs.
for example,
firstName : Victor
THE TWO MECHANISMS ARE:
Session Storage: This maintains a separate storage area as long as the browser is open.
Local Storage: This continues to store data even after the browser is closed.
Both local storage and session storage are properties of the window object which simply represents an open window in a browser.
WHAT REALLY IS LOCAL STORAGE?
Local storage is a property that allows JavaScript sites and apps to save key/value pairs in a web browser.
HOW DOES LOCAL STORAGE WORK?
Local storage works using five simple methods, so hang on as we dive into each of them.
setItem():
This is used to add key and value to local storage.getItem():
This is used to get or extract items from the local storage.removeItem():
This is used to remove an item by key from the local storage.clear():
This is used to clear all data from the local storage.key():
passes a number to retrieve the key of a local storage
"local storage can only store a string. If you want to store an array, you would have to convert it to a string using
JSON.stringify
"
However, local storage is not golden as it has it's own limitations, some of which are:
Local storage cannot be used to store sensitive user information
It is not a substitute for server based database as information is only stored on the browser
Local storage is limited to 5MB across all major browsers
Local storage is quite insecure as it has no form of data protection and can be accessed by any code on your webpage
Local storage is synchronous, meaning each operation called would only execute one after the other
Thanks for reading!. I believe you have been able to get a basic understanding about local storage and the different methods of using local storage.