Categories
Javascript

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.

By Arjun

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

Leave a Reply

Your email address will not be published. Required fields are marked *