URLSearchParams
Build and read query strings with URL and URLSearchParams.
Phase 14 concatenated ?userId= by hand. Prefer
URL + URLSearchParams so encoding and multiple
keys stay correct. Then pass url.toString() to
fetch.
Built URL appears here.
Important JavaScript
const url = new URL("https://jsonplaceholder.typicode.com/posts");
url.searchParams.set("userId", String(userId));
const response = await fetch(url.toString());
// Read: url.searchParams.get("userId")