Posted on Arjun

JavaScript – encodeURI() vs encodeURIComponent()

The purpose of the tutorial is to show you the differences between encodeURI() and encodeURIComponent() functions.

encodeURIComponent()

This method will encode the given string , and if you pass the encoded string to decodeURIComponent(), it will return the original string.

This method will not encode following characters ~!*()'" and it will encode all the characters along with pure URI characters(/ ? : @ & = + $ , – _ . ! ~ * ‘ ( ) #).

This method is helpful, if query string contains URLs.

encodeURI()

This method is not like encodeURIComponent() , it will encode a URL string but not the parameters or hash.

This method will not encode following characters [email protected]#$&*()=:/,;?+' and it will not encode pure URI characters.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.


DMCA.com Protection Status