Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

URLSearchParams.prototype.toString — serializing query parameters

Calling `params.toString()` returns the query parameters as text without a leading `?`. It uses form encoding while preserving order and repeated names.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

params.toString()

URLSearchParams.prototype.toString is the instance method that serializes query parameters. Call it without arguments as params.toString(). The constructor’s URLSearchParams.toString property instead resolves to the inherited Function.prototype.toString method, which does not serialize parameters.

The instance method returns parameter text without a leading ?, not a full URL. An empty list produces "".

Serialization uses application/x-www-form-urlencoded and UTF-8: a space becomes +, and a literal + becomes %2B. Supply unencoded values to avoid encoding % again.

Pairs are joined with &, names and values with =. Order and repeated names are preserved; an empty value produces name=. The method neither sorts nor changes the parameters. This is a Web API from the URL Standard, not an ECMAScript-defined feature.

Examples

const params = new URLSearchParams([
  ["q", "a b+c"],
  ["tag", "js"],
  ["tag", "web"],
  ["empty", ""]
]);
console.log(params.toString());
console.log(JSON.stringify(new URLSearchParams().toString()));

Result

q=a+b%2Bc&tag=js&tag=web&empty=
""

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources