The JavaScript decodeURIComponent Function

The JavaScript decodeURIComponent global function decodes a string previously encoded using the encodeURIComponent function.

Syntax

var decoded_uri_comp = decodeURIComponent(encoded_uri_comp);

Parameters

encoded_uri_comp
An encoded URI component

Description

decodeURIComponent returns a decoded URI component by replacing each UTF-8 escape sequence with the character that it represents.

Example:

decodeURIComponent('~!%40%23%24%25%5E%26*()%3D%2B%5B%5D%7B%7D%5C%3B%3A\'%22%2C%2F%3F');

Output:

~!@#$%^&*()=+[]{}\;:'",/?

JavaScript decodeURIComponent Examples

The JavaScript decodeURIComponent function can be used to decode special reserved characters and other non-ASCII characters such as letters with diacritics or from the Cyrillic alphabet.

Decoding letters with diacritics

Here's an example of decoding a URI component that contains letters with diacritics:

decodeURIComponent("Bj%C3%B6rk%20Gu%C3%B0mundsd%C3%B3ttir");

The above code will output:

Björk Guðmundsdóttir

Decoding Cyrillic letters

Below is an example of decoding a URI that contains Cyrillic letters:

decodeURIComponent("%D0%90%D0%BB%D0%B5%D0%BA%D1%81%D0%B5%D0%B9");

The output of the above code will be:

Алексей

See also

If you see a typo, want to make a suggestion or have anything in particular you'd like to know more about, please drop us an e-mail at hello at diveintojavascript dot com.

Copyright © 2010-2013 Dive Into JavaScript