Home » JavaScript

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]





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.