Structured cloning & URLSearchParams
Deep copy data with structuredClone (keeps Dates/Maps/Sets), and parse/build query strings with URLSearchParams.
Why these tools?
Goal: Copy and serialize URL data safely.
- structuredClone deep-copies data
- Preserves Date/Map/Set
- URLSearchParams parses/builds queries
- Beginner-friendly patterns

Deep copy that keeps types
structuredClone makes a deep copy and keeps Date objects intact.
// Deep copy with structuredClone (Node 17+/modern browsers)
const original = { n: 1, list: [1, 2], when: new Date("2024-01-01") };
const copy = structuredClone(original);
copy.n = 2;
copy.list.push(3);
console.log("original.n:", original.n);
console.log("copy.n:", copy.n);
console.log("dates equal type?", copy.when instanceof Date);

All lessons in this course
- JSON.parse / JSON.stringify basics
- Structured cloning & URLSearchParams
- Safe JSON parsing strategies