The encodeURIComponent() function accepts a string value representing an URI and encodes it by replacing the characters in it using numbers (1 to 4) and escape sequence.
Syntax
Its Syntax is as follows
encodeURIComponent('https://www.qries.com/');
Example
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var result1 = encodeURIComponent('https://www.qries.com/'); document.write(result1); document.write("<br>"); var result2 = encodeURIComponent('https://www.tutorialspoint.com/'); document.write(encodeURIComponent(result2)); </script> </body> </html>
Output
https%3A%2F%2Ffanyv88.com%3A443%2Fhttp%2Fwww.qries.com%2F http%253A%252F%252Fwww.tutorialspoint.com%252F