🚨 Time is Running Out: Reserve Your Spot in the Lucky Draw & Claim Rewards! START NOW

Code has been added to clipboard!

decodeURIComponent

Reading time 2 min
Published Sep 8, 2017
Updated Oct 2, 2019

decodeURIComponent: Main Tips

  • This function is used to decode URI components.
  • The decodeURIComponent() function is useful when you want a URL encoded using encodeURIComponent() to become functional again.

What decodeURIComponent Is

The decodeURIComponent() function is used to decode URI components. In other words, it is useful when you want a quick function for a URL decode. The abbreviation URI refers to a URI.js library used to manage URLs.

As you can see from the example below, once the JavaScript URL decode is applied, the URI is no longer encoded:

Example
var encode = encodeURIComponent(string);
var decode = decodeURIComponent(encode);

Tip: To encode URI components, use encodeURIComponent() function.

DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
edX
Pros
  • A wide range of learning programs
  • University-level courses
  • Easy to navigate
  • Verified certificates
  • Free learning track available
Main Features
  • University-level courses
  • Suitable for enterprises
  • Verified certificates of completion

Correct Syntax

The standard syntax for JavaScript decodeURIComponent function is not complicated. It is easy to understand even for those who are only starting to learn to code. Nevertheless, you should remember the set capitalization of it if you want your code to work and be less difficult to manage:

decodeURIComponent(uri)

As you can see, you should not have any issues when handling decodeURIComponent parameters. The only feature to bear in mind is that the URI parameter must be included. In other words, the function won't know which URI to decode if you won't specify the previous URI, created with encodeURIComponent.

Return Value

As most JavaScript functions, decodeURIComponent() has a return value. To put it simply, it is represents the decoded URI. This value contains textual data, therefore it is classified as a string.

In the example provided above, you have seen the same URI, both encoded and decoded. Review it again to see and understand the differences. Grasp them, memorize the syntax, and you're good to go!