HTML 5 API is providing an amazing feature to handling data locally instead of cookies.
In this article, we are going to look into the HTML 5 Web Storage. Before HTML 5 web storage, we are storing data using Cookies.
After reading this article you will get a deep understanding of local storage
In this article, we are going to look into the HTML 5 Web Storage. Before HTML 5 web storage, we are storing data using Cookies.
After reading this article you will get a deep understanding of local storage
HTML5 has provided an API called web storage, the web storge provides two objects to store the data in a web browser.
- Local storage
- Session storage
Before we are going to use the web storage, need to ensure the browser is having a capability or not,
Using the syntax we can able to find out this. typeof(Storage) !== "undefined".
All the modern browsers are supporting this feature
All the modern browsers are supporting this feature
localStorage Object
Using localStorage we can store the data in the browser without expiration. The data will be available always(day, month, year).
The localStorage data will be available in all the tabs of the browser
The localStorage data will be available in all the tabs of the browser
Methods in localStorage
- setItem - is used to store the data in browser
- getItem - retrieve the data from localStorage
- removeItem - remove the data from localStorage
localStorage.setItem("name","WebStorage");
localStorage.getItem("name")
"WebStorage"
localStorage.removeItem("name");
sessionStorage Object
Session Storage is almost equal to the local storage, but the session storage data will be erased when the user closes the particular tab.
Session storage data are not available in all the tabs, it will be available in particular tab.
Related Articles
- Block scope variables in ES6
- Sorting an array in Javascript
- What is Redux? Why we need Redux? When it is required?
- React - Redux with Example
- What's new in ECMAScript 2019
- Top features in ES 6 / Javascript 2015
Comments
Post a Comment