URL encoding mechanism is used for encoding any data in URLs to a secure format that can be transmitted over the internet.
The encodeURI() function will return a new string representing the given string encoded as a URI. It encodes all the characters except the following ones:
A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #
A-Z a-z 0-9 - _ . ! ~ * ' ( )
The difference between two functions is that the encodeURI() encodes a full URL and encodeURIComponent() encodes a single URL parameter value.
The following examples shows the difference between these two functions: