2 Example(s) of Javascript unescape functions


Description :

unescape function will decode the string. In this example, declare a string with value = "Need javascript tips? Visit LearnKode.com", escape will convert to encrypted string and then unescape will convert back to "Need javascript tips? Visit LearnKode.com". See the code snippet: var str="Need javascript tips? Visit LearnKode.com"; var str_esc=escape(str); document.write(str_esc + "

"); document.write(unescape(str_esc))


Javascript unescape functions Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<script>
var str="Need javascript tips? Visit LearnKode.com";
var str_esc=escape(str);
document.write(str_esc + "<br>");
document.write(unescape(str_esc))
</script>
</body>
</html>

Output

Description :

Example 2 of unescape function:


Javascript unescape functions Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="replaceWithCharacters()">Show the original string</button>
<p id="sample"></p>
<script>
function replaceWithCharacters() {
   var a=unescape("abc123") + "<br>";    
   var b=unescape("%E4%F6%FC") + "<br>";  
   var c=unescape("%u0107") + "<br>";     
    result=a+b+c;
  document.getElementById("sample").innerHTML = result;
}
</script>
</body>
</html>

Output