Home »
JavaScript
encodeURI() and decodeURI() functions with example in JavaScript
JavaScript encodeURI() and decodeURI() functions: Here, we are going to learn about the encodeURI() and decodeURI() functions with Example in JavaScript.
Submitted by IncludeHelp, on February 01, 2019
JavaScript - encodeURI() and decodeURI() functions
These are the two predefined functions or global functions in JavaScript, which are used to encode and decode a URI. encodeURI() is used to encode the URI and decodeURI() is used to decode the URI.
Example
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var uri ="test page.aspx?val=Hello world!!";
var enc_str = encodeURI(uri);
var dec_str = decodeURI(uri);
//printing the values
document.write("Actual URI: " + uri);
document.write("<br>");
document.write("Encoded URI: " + enc_str);
document.write("<br>");
document.write("Decoded URI: " + dec_str);
document.write("<br>");
</script>
</body>
</html>
Output
Actual URI: test page.aspx?val=Hello world!!
Encoded URI: test%20page.aspx?val=Hello%20world!!
Decoded URI: test page.aspx?val=Hello world!!
JavaScript Built-in Functions »