Sobes.tech
Middle

Where in the browser can data be stored on the client side?

sobes.tech AI

Answer from AI

There are several main mechanisms for storing data on the client side in a browser:

  • LocalStorage — simple key-value storage, data persists without expiration, accessible only within the same domain.
  • SessionStorage — similar to LocalStorage, but data only lives within a single session (as long as the tab is open).
  • IndexedDB — a more complex and powerful database on the client side, allows storing large volumes of structured data.
  • Cookies — small pieces of data sent to the server with each request, usually used for sessions and authentication.

Example of using LocalStorage:

localStorage.setItem('user', JSON.stringify({name: 'Ivan', age: 30}));
const user = JSON.parse(localStorage.getItem('user'));
console.log(user.name); // Ivan