Compare unescape(), decodeURI(), and decodeURIComponent() | SJB -->

This website uses cookies to ensure you get the best experience. More info...


Compare unescape(), decodeURI(), and decodeURIComponent()

Compare unescape(), decodeURI(), and decodeURIComponent() | Virtual Species
unescape() Method
     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
We know that escape() method returns a string of the argument with all spaces, punctuation, accented characters and any non-ASCII characters replaced with %HexNumber. The function unescape() does simply the opposite. It takes the encoded version of a string and reverse the string back to its decoded original state. By the way, both of these methods does not work with Unicode strings and both have been deprecated. The syntax of this function is_
For examine, using escape() on the Test Characters will give the following encoded string. Using this encoded string in the input box and decoding will return the original Test String.

decodeURI() Method
     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
The decodeURI() method does the opposite of the encodeURI() method. The encodeURI() method returns encoded string and decodeURI() decode the string as it's decoded original version. The syntax of this function is_
We have discussed on other post that encodeURI() does not encode all the characters (Find More Here). So, some characters don't need to be decoded. Below is the encoded form of our Test Characters. We can copy this in our textbox and by decoding it with the decode button, we will find the original form of the Test Characters.

decodeURIComponent() Method
     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
The encodeURIComponent() function encodes portion of URI by replacing each instance of certain characters by one, two or three of escape sequences. The escape sequences represent the UTF-8 encoding of the characters. We use decodeURIComponent() to reverse the the string encoded by encodeURIComponent(). The syntax of this function is_
Use decodeURIComponent() to decode every strings that encoded with UTF-8 encoding. Below is the encoded form of our Test Characters using this function. Take this encoded string and put into textbox to decode using decode button will generate the original Test Characters.

     Test characters: ~!@#$%^&*=+(){}[],?/:;'\"\\
Decode your URI using all the methods mentioned above_
[ Outputs will be the decoded values of encoded Test Characters unless value is provided ]



decodeURIComponent(): (recommended)

Check out Compare escape(), encodeURI(), and encodeURIComponent()

No comments:

Post a Comment