decodeURIComponent
Decodes a URI component previously created by encodeURIComponent or by a similar routine
Syntax
decodeURIComponent(encodedURI)Parameters
| Parameter | Type | Description |
|---|---|---|
| encodedURI | string | An encoded component of a URI |
Return Value
A new string representing the decoded version of the encoded URI component
Examples
console.log(decodeURIComponent('Hello%20World')); // 'Hello World'
console.log(decodeURIComponent('a%3D1%26b%3D2')); // 'a=1&b=2'const params = new URLSearchParams('q=hello%20world&page=1');
console.log(decodeURIComponent(params.get('q')!)); // 'hello world'function parseQueryString(qs: string) {
return Object.fromEntries(
qs.split('&').map(p => p.split('=').map(decodeURIComponent))
);
}Understanding decodeURIComponent
The decodeURIComponent method in JavaScript decodes a URI component previously created by encodeURIComponent or by a similar routine. It belongs to the window object and is one of the most widely used methods for working with window values in modern JavaScript and TypeScript applications.
The method signature is decodeURIComponent(encodedURI). It accepts 1 parameter: encodedURI. When called, it returns a new string representing the decoded version of the encoded uri component. Understanding when and how to use decodeURIComponent() helps you write more expressive, readable code.
Common use cases for decodeURIComponent include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like window-encodeuricomponent, window-decodeuri, window-encodeuri, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for decodeURIComponent is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
encodeURIComponentEncodes a URI component by replacing certain characters with UTF-8 escape sequences
decodeURIDecodes a Uniform Resource Identifier previously created by encodeURI or by a similar routine
encodeURIEncodes a URI by replacing certain characters with UTF-8 escape sequences, but preserves characters that are part of URI syntax
More Global / Window Methods
Other methods in the Global / Window object
Related Tools
More Global / Window Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.