2 Example(s) of Javascript escape functions


Description :

escape function will encode the string. In this example, "Need javascripttips? Visit LearnKode.com!" will get converted to "Need%20javascripttips%3F%20Visit%20LearnKode.com%21". See the code snippet:


Javascript escape functions Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<script>
document.write(escape("Need javascripttips? Visit LearnKode.com!"));
</script>

</body>
</html>

Output

Description :

Example 2 of escape function


Javascript escape functions Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="replaceCharacters()">Computes new string</button>
<p id="sample"></p>
<script>
function replaceCharacters() {
   
  var a=escape("abc123") + "<br>";    
  var b=escape("äöü") + "<br>";        
  var c=escape("c") + "<br>";          
  var d=escape("@*_+-./") + "<br>";    
  result=a+b+c+d;
  document.getElementById("sample").innerHTML = result;
}
</script>

</body>
</html>

Output