# localStorage & sessionStorage — JavaScript

Source: https://www.geekswithgeeks.com/en/javascript/js-storage

> Saving small amounts of data directly in the browser.

## Saving & reading data

A simple key-value API that survives page reloads.

```js
localStorage.setItem("theme", "dark");
console.log(localStorage.getItem("theme"));  // "dark"
localStorage.removeItem("theme");
```

## local vs session

`localStorage` persists across browser restarts; `sessionStorage` clears when the tab closes. Both only store strings.

## Storing objects

Use `JSON.stringify()` before storing an object and `JSON.parse()` after reading it back — storage only holds strings.
