Save it and fetch it
Cheat sheet · Level 1
Remember it
Every command and idea of this level on one page: what to type, what it does, and what you see.
1Save it on the phone
Keep a value after the app closes.
What to type What it does You see localStorage.setItem("name", input.value);Save the name on the phone · 2Read it back
Open the app and find your name.
What to type What it does You see const name = localStorage.getItem("name");Read the saved name Welcome back, Mia 3A brand-new phone
Nothing saved? Use a default.
What to type What it does You see const name = localStorage.getItem("name") || "friend";A default when nothing is saved Welcome back, friend 4Save the whole list
Turn a list into text first.
What to type What it does You see localStorage.setItem("items", JSON.stringify(items));Turn the list into text ["Milk","Eggs"] 5Open with the list ready
Turn the text back into a list.
What to type What it does You see let items = JSON.parse(localStorage.getItem("items") || "[]");Turn the text back into a list · 6Start a new list
Delete what was saved.
What to type What it does You see localStorage.removeItem("items");Delete the saved list · 7On your own: the reading log
Make it remember.
What to type What it does You see let books = JSON.parse(localStorage.getItem("books") || "[]");Start from the saved list · localStorage.setItem("books", JSON.stringify(books));Save after each Add · localStorage.removeItem("books");Clear deletes the jar ·