View Discussion Show Improve Article Save Article View Discussion Improve Article Save Article JavaScript is one of the world’s most popular lightweight, interpreted compiled programming languages. It is synchronous and single-threaded. In JavaScript, the programs are called scripts. These scripts are executed as plain text. We can write them directly on our HTML page or use an external Javascript file. JavaScript can execute in the browser, and also on the server, or actually on any device that has a special program called the JavaScriptengine. JavaScript is used for both client-side and server-side developments. HTML DOM Window localStorage is provided by Browser and it allows us to store data as key-value pairs in our web browser using an object. The localStorage is the read-only property of the window interface. Data is stored as key-value pair and the keys are unique. The keys and the values are always in the UTF-16 DOM String format that is stored within localStorage. The main features of localStorage are:
Syntax: ourStorage = window.localStorage; The above will return a storage object which can be used to access the current origin’s local storage space. Properties and methods provided by the localStorage object:
Example: The following snippet accesses the current domain’s localStorage object. HTML
Output: Note: To view the data in the browser’s Local Storage, do the following.
Why do we need local storage in JavaScript?Local storage allows developers to store and retrieve data in the browser. The data stored in local storage will not expire. This means the data will persist even if the tab or the browser window is closed.
When should you use localStorage?To keep it short, here's the only situation in which you should use local storage: when you need to store some publicly available information that is not at all sensitive, doesn't need to be used in a high performance app, isn't larger than 5MB, and consists of purely string data.
What do you mean by local storage?A hard drive or solid state drive (SSD) directly attached to the device being referenced. The term would be used to contrast the storage in that unit from the storage on servers in the local network or on the Internet (see SAN, NAS and cloud storage).
Is localStorage a cookie?The two have different purposes, and hence different strengths and weaknesses. Cookies are intended to be read by the server, whereas localStorage can only be read by the browser. Thus, cookies are restricted to small data volumes, while localStorage can store more data.
|