Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
You need to deep-copy an object that contains a Date and a Map, preserving their real types. Which approach correctly preserves them?
💻 Code Challenge | +75 XP
Write a function that fetches query parameters from a request URL string using the native URL class, increments a "page" parameter by 1, and returns the updated URL as a string.
A deep-clone using JSON.parse(JSON.stringify(obj)) is silently converting a Date field into a plain string. Reorder these steps to fix it properly.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Using JSON.parse(JSON.stringify(obj)) to deep clone an object containing Dates, Maps, or Sets
// Wrong: Date becomes a string, Map becomes {}
const copy = JSON.parse(JSON.stringify({ date: new Date(), m: new Map() }));
// Correct
const copy = structuredClone({ date: new Date(), m: new Map() });The Solution //
JSON serialization silently converts Dates to ISO strings, drops undefined values and functions entirely, and cannot represent Map or Set at all — producing a "clone" with a different shape than the original. structuredClone() is the standards-based deep-clone that correctly preserves all of these types.
The Error //
Manually parsing query strings with string.split("&") and split("=") instead of URLSearchParams
// Wrong: breaks on encoded characters and edge cases
const page = queryString.split("&").find(p => p.startsWith("page=")).split("=")[1];
// Correct
const url = new URL(fullUrl);
const page = url.searchParams.get("page");The Solution //
Manual query-string parsing breaks on edge cases the spec already handles correctly — URL-encoded characters, repeated keys, and empty values. The built-in URL and URLSearchParams classes handle encoding/decoding and edge cases correctly with far less code and no custom regex to maintain.