What you're building
Two functions:
parseQS(queryString)— decode"name=Alice&age=30"into{ name: "Alice", age: "30" }stringifyQS(obj)— encode{ name: "Alice", age: "30" }back to"name=Alice&age=30"
Query strings power every web URL, form submission, and REST API you will ever
work with. Knowing what encodeURIComponent / decodeURIComponent do — and why
they exist — is essential for a working web developer.
Requirements
parseQS:
- Split on
&to get key-value pairs - Split each pair on the first
=only - Decode percent-encoded characters with
decodeURIComponent - Ignore pairs with no
= - Return a plain object
stringifyQS:
- Encode both key and value with
encodeURIComponent - Join pairs with
& - Return the query string (no leading
?)
Stretch goals
- Handle repeated keys as arrays:
color=red&color=blue→{ color: ["red","blue"] } - Support a leading
?in the input toparseQS
What this proves
- You can read and write the fundamental unit of web communication
- You understand URL encoding and why special characters must be escaped
- You've implemented a utility that ships in every HTTP library
⚡ 40 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
parseQS basic key-value pairs
parseQS decodes percent-encoding
stringifyQS encodes special chars
round-trip: stringify then parse
Run your code to check these.