Code Literacy

Unit 7 · Data that lasts

localStorage vs a database: where data lives

localStorage is a small notepad inside one person’s browser on one device; nobody else can read it, and it vanishes if they clear their data. A database lives on a server, is backed up, and is the same from every device.

The mix-up

What people often think

“localStorage is a small database.”

What the tutor says

A database is shared and lives on a server. localStorage is a notepad inside one person's browser, and nobody else can read it.

Where would the bakery owner go to see today's orders?

How it works

Ask who needs to see the data. A bakery’s orders must be visible to the bakery, so they belong in a server database; orders saved in each customer’s browser never leave it. Accounts have to work from any device and be checked by the site, so they belong on the server too.

Not everything needs a database. A visitor’s own preference, like dark mode or whether a menu is open, is fine in their browser. Sending it to a server adds work for nothing.

Close cousins of this mix-up

The tutor watches for these in the same lesson.

  • “localStorage is the most permanent place, because it lives on my own computer.”

    localStorage vanishes if the person clears their browser data or switches devices. A server database is backed up and the same from every device.

  • “Orders can sit in the customer's browser, since that is where they placed them.”

    The bakery needs to see every order from its own computer. Data in a customer's localStorage never leaves that customer's browser.

  • “Saving accounts in localStorage is a quick way to remember who signed up.”

    Accounts must work from any device, and the site must check them. Only a server database can do both.

  • “Everything should be saved to the database, just in case.”

    Whether a menu is open matters for a few seconds. Sending it to a server adds work and slows the page for nothing.

Practise it with a tutor watching

Why a database

Say where a piece of data should live: page memory, the browser, or a database on a server.

15 minutes See it Build it Break it Say it
Start the lesson

Free with an account. The first two units need no account.

© 2026 webfaCeMEdia. Code Literacy™ is a trademark of webfaCeMEdia.