encodeURIComponent() function in JavaScript


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('http://www.qries.com/');

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result1 = encodeURIComponent('http://www.qries.com/');
      document.write(result1);
      document.write("<br>");
      var result2 = encodeURIComponent('http://www.tutorialspoint.com/');
      document.write(encodeURIComponent(result2));
   </script>
</body>
</html>

Output

http%3A%2F%2Fwww.qries.com%2F
http%253A%252F%252Fwww.tutorialspoint.com%252F

Updated on: 25-Jun-2020

53 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements