uri – We can pass any data types like string, number, boolean, object, etc because before escaping it will be converted into a string.
It will return a string in which special characters are escaped.
In the above example, we escape our special characters string by using the encodeURIComponent() method.
The encodeURIComponent() method escapes all the characters except the below characters.
* ‘ ( )- _ . ! ~0-9 A-Z a-z – These characters will not be escaped by the encodeURIComponent() method.
So in the above example, we can see encodeURIComponent replaced all the characters with UTF-8 characters or hexadecimal characters except the above characters.
In the url query, we don’t need any special characters like space, etc. So by using these methods we escape those characters. Which characters you must and which you mustn’t escape indeed depends on the regex flavor you’re working with.
Character escaping is what allows certain characters to be literally searched for and found in the input string.
That’s it for this tutorial.