Todo App
Build a fully functional Todo app — the classic starter project. This project teaches state management, DOM rendering, CRUD operations, event handling, filtering/sorting, and localStorage persistence.
What You Will Build
State & CRUD
Add, edit, toggle, delete todos with immutable state updates
Filter & Sort
All / Active / Done / High Priority, sort by date/priority/alpha
Persistence
Save to localStorage, load on startup, handle storage errors
Stats & UX
Completion rate, counts by priority, keyboard shortcuts
Core Concepts Demonstrated
Immutable State Updates
Always create new arrays — todos = todos.filter(...) — never mutate in place. Makes debugging easier.
Derived State
Active count, completion rate, filtered list — computed from source array, not stored separately.
Event Delegation
One listener on <ul> handles all item clicks. No re-binding listeners after re-renders.
Optimistic UI
Update UI immediately, persist to storage after. Feels instant even on slow devices.
Input Validation
Trim whitespace, reject empty strings, limit length. Always validate before adding to state.
Error Isolation
localStorage.setItem can throw (QuotaExceededError). Wrap in try/catch, degrade gracefully.
Common Pitfalls
Build It Live
Code Editor
<form id="form"><input id="text" placeholder="What needs doing?"><button>Add</button></form>
<div id="filters"><button data-f="all">All</button><button data-f="open">Open</button><button data-f="done">Done</button></div>
<ul id="list"></ul>
<p id="count"></p>Preview
Todo App — step by step
State as the Source of Truth
Store your todo items in a JavaScript array (the state). The UI is a function of that array — never mutate the DOM directly. When state changes, re-render the list from scratch or use diffing to update only changed nodes.
🎯 Quick Check
What is the recommended way to remove a todo item from a state array?
Next project