---
# System prepended metadata

title: Why to use Local Storage

---





## Local Storage
LocalStorage is a type of web storage that allows Javascript websites and apps to store and access data right in the browser with no expiration date. This means the data stored in the browser will persist even after the browser window has been closed.
# Why to use Local Storage
as an example when we use an application and then close it, its state will be reset the next time you open it. If you close an application on your desktop and re-open it, its most recent state is restored.

## Session storage
sessionStorage is similar to localStorage; the difference is that while data in localStorage doesn't expire, data in sessionStorage is cleared when the page is closed, so it is tab depending.

# Why to use Session Storage
* Some things you only want the user to see once per login, like a news popup. You could store that they've seen it already in sessionStorage. This would also work for actions that you only want the user to do once per login.
* another use Session Storage is to give the user ability to open the same page in differente tabs and give him differente information in each.



## Cookies
The website stores a corresponding file called cookies to the one they set in your browser and in this file they can track and keep information on your movements within the site and any information you may have voluntarily given while visiting the website, such as email address.
# Why to use Cookies
as defintion cookies used to track and keep information on your movements within the site.


## differnce between localstorage,session storage and cookie


| | cookie | local storage | session storage|
|--------| -------- | -------- | -------- |
|expired | depending to defnition  | manual delete (in code)| browser closed|
| size |5 KB| 5MB|5 MB|
|avalibality|all pages|all pages|current page|
|saved in|client|client|client|
|Can be accessed on|both|only client|only client|
## Why to use cookie instead of Local/Session Storage
Cookies are mainly for reading server-side, whereas local storage can only be read by the client-side, because this fact that the cookies can read from both server and client sides make it more powerful from localstorage.