Browsers offer several ways to remember data.
Direct answer
localStorage keeps data until cleared. sessionStorage keeps it until the tab closes. Cookies are small pieces of data sent to the server with requests. IndexedDB stores larger structured data. Choose based on how long you need the data, how much, and whether the server needs it.
Comparison
| localStorage | sessionStorage | Cookies | IndexedDB | |
|---|---|---|---|---|
| Lasts | until cleared | until tab closes | set by expiry | until cleared |
| Sent to server | no | no | yes | no |
| Size | a few MB | a few MB | very small | much larger |
| Data type | strings | strings | strings | structured |
Safety
Do not store passwords or sensitive tokens in localStorage or sessionStorage. Use secure, HTTP-only cookies for authentication where appropriate.
Where Teyro fits
Teyro's Interactive Web Pages with JavaScript course turns this into short lessons you can play in a few minutes a day. It has 37 lessons, and you can start free.
The bottom line
Pick the simplest tool that fits the job.



