Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

decodeURIComponent

Decodes text that was encoded for a URL.

Available since: ES3

Syntax

decodeURIComponent(encodedStr)

Parameters

ParameterTypeDescription
encodedStrstringA string with codes like %20.

Return value

stringThe decoded text.

Examples

The reverse conversion:

console.log(decodeURIComponent('rock%20%26%20roll'));
console.log(decodeURIComponent('caf%C3%A9'));

Output:

rock & roll
café

An invalid code throws an error:

try {
  decodeURIComponent('100%');
} catch (error) {
  console.log(error.name);
}

Output:

URIError

Notes

This function does not turn + into a space, although forms encode spaces that way. Read form parameters with URLSearchParams instead.

See also

In the tutorial

  • Server requests: fetch — The fetch function in JavaScript: GET and POST requests, the response object, status, response.ok, parsing JSON and handling errors.

Thanks for reading!

Donate to the site — we work hard for you.