Hello devs, today we'll learn about the encodeURI() function. How its works or when we need them.
The function replaces each instance of certain characters with its corresponding URI encoding. Characters that are not ASCII letters, digits, or one of the following characters: ; , / ? : @ & = $ - _ . ! ~ * ' ( ) #, are replaced with a percent sign ("%") followed by two hexadecimal digits that represent the ASCII code of the character.
Here's an example:
let uri = 'shouts.dev?name and author=tanvir&age=25#link' let coded = encodeURI(uri); console.log(coded);
Which will produce the below result:
It can be helpful for generating a valid URI for specially non-ASCII character which is not supported by other systems.
That's it for today. I hope you've enjoyed this tutorial. Thanks for reading. 🙂
No comments yet…