Home » JavaScript

escape() function with example in JavaScript

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

While transferring the data over the network or sometimes while saving data to the database, we need to encode the data. The function escape() is a predefined function in JavaScript, which encodes the given string.

It encodes almost all special characters including spaces.

Note: escape() function does not encode some of the special characters like @+-/.*_

Example:

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

<body>
	<script>
		str = "Hello world!";
		//Actual string
		document.write("Actual string is: " + str);
		document.write("<br>");
		//encoded string
		document.write("Encoded string is: " + escape(str));
		document.write("<br>");

		//assign another string
		str = "email id: [email protected]";
		//Actual string
		document.write("Actual string is: " + str);
		document.write("<br>");
		//encoded string
		document.write("Encoded string is: " + escape(str));		
	</script>
</body>
</html>

Output

Actual string is: Hello world!
Encoded string is: Hello%20world%21
Actual string is: email id: [email protected]
Encoded string is: email%20id%3A%[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.