Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

URLSearchParams.has() — checking parameter presence

URLSearchParams.has() checks whether a parameter name or a name–value pair exists. It returns true or false without changing the parameters.

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.has(name)
params.has(name, value)

params.has(name) returns true if a parameter with that name exists. In a runtime that supports value matching, params.has(name, value) requires the name and value to match within the same pair, provided that value is not undefined. Explicitly passing undefined as the second argument is equivalent to omitting it: params.has(name, undefined) checks only the name. With repeated names, one matching pair is sufficient; the method does not modify data.

Matching is case-sensitive and uses decoded strings, not query substrings. Parsing treats + as a space. An empty value still means the parameter exists: for empty=, has("empty") returns true.

This is a Web API from the WHATWG URL Standard, not a feature of a particular ECMAScript edition. The specification alone does not establish target-browser support; Node 24 in the repository does not prove it either. Check the value variant separately.

Examples

const params = new URLSearchParams("tag=js&tag=web&empty=&q=a+b");
console.log(params.has("tag"));
console.log(params.has("tag", "web"));
console.log(params.has("tag", "css"));
console.log(params.has("empty"));
console.log(params.has("missing"));
console.log(params.has("q", "a b"));

Result

true
true
false
true
false
true

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