SyntaxStudy
Sign Up
JavaScript Query Parameters with URLSearchParams
JavaScript Beginner 3 min read

Query Parameters with URLSearchParams

Query Strings

URLSearchParams builds and encodes query strings safely, handling special characters automatically.

Example
const params = new URLSearchParams({ search: "hello world", page: 2, limit: 20 });
const url = `/api/users?${params}`;
// /api/users?search=hello+world&page=2&limit=20
const fullUrl = new URL("/api/users", "https://example.com");
fullUrl.searchParams.set("role", "admin");
await fetch(fullUrl.toString());
Pro Tip

Never concatenate query strings manually — URLSearchParams handles encoding correctly.