Persistence with localStorage
중급~30 분0/4 단계
Keep the ledger after refresh
Browser memory disappears when a page reloads. localStorage gives a small local-first application durable storage on the same device. Arrays must be serialized to JSON when saved and parsed when loaded.
Parsing can fail if stored data is damaged, so recovery is part of the feature—not an afterthought.
안내
1
Create loadTransactions with localStorage.getItem and JSON.parse.
힌트: Read STORAGE_KEY, then parse only when raw exists.
2
Recover safely with try/catch and return an empty array on failure.
3
Create saveTransactions(items) with JSON.stringify.
4
Save after every push and render once on startup.
내 코드
html
1
2
3
4
5
ViBot과 함께 바이브로 만들기무료 메시지 0 / 12개
이 단계에서 만들고 싶은 것을 설명해 주시면 코드를 작성해 드릴게요 — 그다음 적용을 클릭하면 에디터에 바로 들어갑니다. 이 단계: Create loadTransactions with localStorage.getItem and JSON.parse.
실시간 미리보기
실시간 미리보기