What is difference between a SessionStorage, Cookie, and LocalStorage.

Macy Graham-Kimbrough
Macy Graham-Kimbrough

Posted On: Jan 07, 2021

 

LocalStorageSession storageCookie
localStorage is a way to store data on the client’s computer. It allows the saving of key/value pairs in a web browser and it stores data with no expiration date. localStorage can only be accessed via JavaScript and HTML5. However, the user has the ability to clear the browser data/cache to erase all localStorage data. It has key-value storage, where we have key and value as a serialized object. It has LocalStorage API from the console and it will create a key-value pair in the LocalStorage store.Session storage stores data only for a session, meaning that the data is stored until the browser (or tab) is closed. Session storage data is never transferred to the server. It can only be read on the client-side. Its storage limit is about 5-10MB. It provides opening multiple tabs/windows with the same URL creates sessionStorage for each tab/window.Cookie stores data that has to be sent back to the server with subsequent XHR requests. Its expiration varies based on the type and the expiration duration can be set from either server-side or client-side. Cookies are primarily for server-side reading (can also be read on client-side), localStorage and sessionStorage can only be read on the client-side. Size must be less than 4KB. Cookies can be made secure by setting the httpOnly flag true for that cookie. This prevents client-side access to that cookie. Cookies can be updated and set using document.cookie object from browser window object.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Front End Developer Interview Questions

    What is HTML?

    HTML (HyperText Markup Language) is a markup language to design the web page. It is used to display the contents of the web page in order. They are the building blocks of the HTML pages. This text-bas...

    Front End Developer Interview Questions

    What is Ajax?

    Ajax (Asynchronous Javascript and XML) is a technique to create asynchronous web applications. Applications developed with Ajax can send and retrieve data asynchronously from the server without interf...

    Front End Developer Interview Questions

    What is npm?

    NPM stands for Node Package Manager. It is used to install, uninstall, update packages for Javascript Programming Language. NPM also is a default package manager for Node.js....