2017  Kodetalk | Feedback | Privacy Policy | Terms | About

What is localStorage and sessionStorage in HTML5 or Web Storage?

What is localStorage and sessionStorage in HTML5 or Web Storage.
In HTML5 web storage is to store web page data locally within the user’s browser.
Web Storage is more secure and faster where earlier we used to use cookies for storage. The data used when code requires for.
Basically the data stored as name/value pairs, and a web page can only access data stored by itself. The storage limit is far larger (at least 5MB) and information is never transferred to the server.

The difference between localStorage and sessionStorage involves the lifetime and scope of the storage. Data stored through localStorage is permanent: it does not expire and remains stored on the user’s computer until a web app deletes it or the user asks the browser to delete it. sessionStorage has the same lifetime as the top-level window or browser tab in which the script that stored it is running. When the window or tab is permanently closed, any data stored through sessionStorage is deleted. Both forms of storage are scoped to the document origin so that documents with different origins will never share the stored objects. But sessionStorage is also scoped on a per-window basis. If a user has two browser tabs displaying documents from the same origin, those two tabs have separate sessionStorage data the scripts running in one tab cannot read or overwrite the data written by scripts in the other tab, even if both tabs are visiting exactly the same page and are running exactly the same scripts.
Answer is