# localStorage & sessionStorage — JavaScript Fundamentals: From Syntax to Async

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

> Save small data in the browser with localStorage and sessionStorage and store objects as JSON.

## 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.
