You can encode a string using the escape() function in JavaScript. It makes a string portable to be transmitted across any network to any computer that supports ASCII characters.
escape(string)
JavaScript escape string Using escape function
HTML example code, how to special character encoded with escape function
<!DOCTYPE html>
<html>
<body>
<script>
document.write(escape("EyeHunt tuorial!!!"));
document.write("<br>");
document.write(escape("A tuorial site for develoeprs"));
</script>
</body>
</html>
Output:
Note: Although escape()
is not strictly deprecated (as in “removed from the Web standards”), it is defined in Annex B of the ECMA-262 standard, whose introduction states:
Note: This function only encodes the special characters, this function is deprecated.
Exceptions: @ – + . / * _
Do comment if you have any doubts or suggestions on this JS escape topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version