LocalStorage is a special object used to store some information in the browser. It is a great tool to store user login information and some temporary key-value pair. It is similar to Cookie and very different to Session because LocalStorage is also unencrypted. LocalStorage also there after user refresh the page, so it is a can be used to store some unimportant information to keep user login or do some validation. Because it is unencrypted, so it batter use to do something not too important.
There are some function can be called on LocalStorage.
localStorage.setItem(key, value) ,
localStorage.removeItem(key) . SetItem is used to store one key-value pair. Clear will clear all the items in the LocalStorage on this website. RemoveItem will clear one Item on this website by using a correspond key. Then let have some examples.
Let say, I want to save some information like a username for the future use.
I can put them in the localStorage like this.
If we check it in our Console in Chrome we will have something like this.
We can use this information in our future function by just calling
localStorage.userName and not finding the tag with the dataset. If we are done using this information we can use
If user logout, we can just use
And finally this.