JavaScript · Senior · Question 44 of 75

What's the right way to build a query string from a params object?

Explanation

URLSearchParams correctly encodes spaces, non-ASCII characters and special characters like &, which would break the request or allow parameter tampering with manual concatenation. The URL object lets you work with the whole address: url.searchParams.set('page', 2).

Further reading

Problem with a question

JavaScript · Senior · question 44

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz