Querystring Helper 1: Implement parseQueryString

easy
By FrontendAtlas Editorial · Updated Oct 10, 2026
Implement parseQueryString(qs) that converts a URL querystring into a plain object. This is very common in frontend work (filters, pagination, deep links) and shows up in interviews. Rules (Easy version): 1) Input may start with ?. 2) Pairs are separated by &. 3) Each pair is key=value. 4) Decode percent-encoding with decodeURIComponent. 5) + should be treated as a space. 6) If a key appears multiple times, keep the last value. 7) If a pair is missing =, treat value as empty string. 8) Empty keys should be ignored. No arrays, no nested objects in this version.

Arguments

  • qs: string — Querystring like "?a=1&b=two" or "a=1".

Returns

Record<string, string> — An object mapping each key to its decoded string value.

Solution idea

Normalize a querystring into key/value pairs, decode each piece, and build an object where later keys overwrite earlier ones. Handle leading ?, treat + as space, ignore empty keys, and treat missing = as an empty string. This is a realistic parsing task used for filters, pagination, and deep links.

Examples
parseQueryString('?a=1&b=two'); // => { a: '1', b: 'two' }

parseQueryString('q=hello+world'); // => { q: 'hello world' }

parseQueryString('a=1&a=2'); // => { a: '2' }

parseQueryString('flag'); // => { flag: '' }