unescape() function with example in JavaScript

JavaScript unescape() function: Here, we are going to learn about the unescape() function with example in JavaScript, how and when it is used?
Submitted by IncludeHelp, on February 01, 2019

If we have an encoded data which has been encoded using the escape() function, and we need the actual data, in such case – we use unescape() function. This is also a predefined function in JavaScript and returns decoded data which has been encoded using the escape() function.

Example:

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>
		//Actual string
		str1 = "Hello world!";
		//encoded string
		str2 = escape(str1);
				
		document.write("Actual string is: " + str1);
		document.write("<br>");
		document.write("Encoded string is: " + str2);
		document.write("<br>");		
		//decoding the string
		str3 = unescape(str2);
		document.write("Decoded string is: " + str3);
		document.write("<br>");				

		//Actual string
		str1 = "email id: [email protected]";
		//encoded string
		str2 = escape(str1);
				
		document.write("Actual string is: " + str1);
		document.write("<br>");
		document.write("Encoded string is: " + str2);
		document.write("<br>");		
		//decoding the string
		str3 = unescape(str2);
		document.write("Decoded string is: " + str3);
		document.write("<br>");
	</script>
</body>
</html>

Output

Actual string is: Hello world!
Encoded string is: Hello%20world%21
Decoded string is: Hello world!
Actual string is: email id: [email protected]
Encoded string is: email%20id%3A%[email protected]
Decoded string is: email id: [email protected]

JavaScript Built-in Functions »





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.