# How to decode a URL using JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Feb 26, 2020, updated Oct 13, 2022. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-decode-url

> A quick guide to learning how to decode URLs or query string parameters in JavaScript using native functions.

In an [earlier article](https://attacomsian.com/blog/javascript-encode-url), we looked at different ways to encode a URL in JavaScript. In this article, you'll learn how to **decode an encoded URL** in JavaScript.

URL decoding is the *opposite* of the encoding process. It converts the encoded URL strings and query parameters back to their original formats. Mostly encoded query string parameters are automatically decoded by the underlying framework you're using, like Express or Spring Boot. However, in standalone applications, you have to manually decode query strings.

Let us look at the JavaScript native functions that can be used for this purpose.

## `decodeURI()` method

The `decodeURI()` function is used to decode a full URL in JavaScript. It performs the *reverse* operation of `encodeURI()`.  Here is an example:

```javascript
const encodedUrl = 'http://example.com/!leearn%20javascript$/'

// decode complete URL
const url = decodeURI(encodedUrl)

// print decoded URL
console.log(url)

// output: http://example.com/!leearn javascript$/
```

## `decodeURIComponent()` method

The `decodeURIComponent()` function is used to decode URL components encoding by `encodeURIComponent()` in JavaScript. It uses the `UTF-8` encoding scheme to perform the decoding operation.

The `decodeURIComponent()` method is suitable for decoding query string parameters and path segments instead of a complete URL. 

Here is an example:

```javascript
const query = 'Danke Schön'

// perofrm encode/decode
const encodedStr = encodeURIComponent(query)
const decodedStr = decodeURIComponent(encodedStr)

// print values
console.log(`Encoded Query: ${encodedStr}`)
console.log(`Decoded Query: ${decodedStr}`)

// Output
// Encoded Query: Danke%20Sch%C3%B6n
// Decoded Query: Danke Schön
```

**Read Next:** [Base64 encoding and decoding in JavaScript](https://attacomsian.com/blog/javascript-base64-encode-decode)
