Now the alternative to encodeURIComponent is. This will take an encoded string like the one in the previous example, and take all the special characters, like %20, and convert them back into their original values, in this case space. For this, inside of decodeURIComponent once again we'll pass a string.
Let's go ahead and type our first and last name. In my case it's Andrew, and instead of a space between them I'll add %20, which we know is the encoded character for a space. Since we're trying to decode something, it's important to have some encoded characters here. Once yours looks like the following code with your first and last name, you can go ahead and hit enter, and what we get back is the decoded version:
decodeURIComponent('Andrew%20Mead')
As shown in the following code output, I have Andrew Mead with the %20 being replaced by the space, exactly what we expected. This is how we can encode and decode URI components in our app:
