JavaScript Notes
Learn to build a notes app in JavaScript with create, edit, delete, search, pin, and localStorage persistence. Covers markdown preview and color coding.
What You'll Learn
- How to create, read, update, and delete notes stored as objects in an array
- How to implement real-time search that filters notes by content or title
- How to auto-save notes as the user types with
inputevents - How to pin important notes so they stay at the top
- How to persist all notes with
localStorage
Project Overview
A notes app lets users jot down thoughts quickly. Notes are displayed as cards in a grid. Each note has a title, body, timestamp, optional color tag, and a pin toggle.
Component Structure
How It Works — Flow Diagram
Step-by-Step Build
Step 1 — HTML Structure
<div class="notes-app">
<header class="notes-header">
<h1>Notes</h1>
<div class="header-controls">
<input type="search" id="searchInput" placeholder="🔍 Search notes...">
<button id="newNoteBtn" class="btn-new">+ New Note</button>
</div>
</header>
<main id="notesGrid" class="notes-grid"></main>
</div>Step 2 — State
Step 3 — Create Note
function createNote() {
const note = {
id: Date.now(),
title: "",
body: "",
color: "default",
pinned: false,
updatedAt: Date.now()
};
notes.unshift(note); // add to front
saveNotes();
render();
// focus the first note's title after render
const firstTitle = document.querySelector(".note-card .note-title");
if (firstTitle) firstTitle.focus();
}
document.getElementById("newNoteBtn").addEventListener("click", createNote);Step 4 — Render Notes Grid
Step 5 — Event Delegation on Grid
Step 6 — Search
Step 7 — Helpers & Persistence
function saveNotes() {
localStorage.setItem("notes", JSON.stringify(notes));
}
function formatDate(ts) {
return new Date(ts).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
}
function escapeHtml(s) {
return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
}
function escapeAttr(s) {
return s.replace(/"/g, """);
}Step 8 — Initialize
render();Console Output
// User clicks "+ New Note"
createNote() → notes = [{ id: 1749686400000, title: "", body: "", pinned: false }]
render() → 1 note card shown, title field focused
// User types title "Meeting Notes" and body "Discuss Q2 budget"
input → note.title = "Meeting Notes"
input → note.body = "Discuss Q2 budget", updatedAt updated
saveNotes() → localStorage updated on every keystroke
// User pins the note
note.pinned = true
render() → pinned card moves to front, 📌 icon highlighted
// User searches "meeting"
searchQuery = "meeting"
render() → only "Meeting Notes" card visibleEdge Cases to Handle
| Situation | Expected Behavior |
|---|---|
| Empty note (no title or body) | Still saved — user may fill it later |
| Search with no results | "No notes match your search" message |
| Delete last note | Empty state message shown |
| Very long body | textarea scrolls naturally |
| XSS in content | Escape HTML before render |
Challenge Yourself
- Markdown preview — add a toggle between edit and rendered markdown mode
- Drag-to-reorder — let users rearrange note cards
- Export as TXT — download note content as a
.txtfile - Labels / tags — let users assign and filter by custom tags
- Cloud sync — store notes in Firebase or a REST API
Best Practices
- Auto-save on input rather than requiring a Save button
- Use event delegation on the grid container — never attach listeners to individual cards
- Avoid full re-renders on every keystroke — update only the affected DOM elements
- Sort pinned notes first every render cycle
- Escape user content before inserting as HTML to prevent XSS
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Build a JavaScript Notes App - Step by Step Project Tutorial.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this JavaScript Master Course topic.
Search Terms
javascript-complete-guide, javascript master course, javascript, complete, guide, mini, projects, notes
Related JavaScript Master Course Topics