Local storage
We have looked at cookies as a way to save user data, but there is actually a more modern way to do this: local storage. Local storage is an amazing fun topic that will add to your ability to make smart websites. With local storage, we can save key-value pairs in our web browser and use them again in a new session (when the browser is opened again later). The information is typically stored in a folder on the computer of the user, but this differs a bit by browser.
This allows the website to store some information and retrieve it later, even after refreshing the page or closing the browser. The advantage of local storage over cookies is that they don't need to be passed around with every HTTP request, which is the case with cookies. Local storage just lives there and waits to be accessed.
The localStorage
object is a property of the window
object that we have seen before. There are a few methods on the localStorage
object that we need to know to use it effectively...