Explain the functions of Unescape () and String () in JavaScript, and explain criptunescape
The functions of JavaScript SCAPE () and String () in JavaScript are described as follows:
Definition and usage
The JavaScript unescape () function can decode strings encoded by escape.
Syntax
Unescape (string)
Parameters |
Description |
String |
Required. The string to be decoded or reversed. |
Return Value
String is a decoded copy.
Description
This function works like this: Find the character sequence in the form of % xx and % uxxxx (x indicates a hexadecimal number ), use Unicode characters \ u00xx and \ uxxxx to replace such character sequences for decoding.
Tips and comments
Note: ECMAScript v3 has removed the unescape () function from the standard and is opposed to using it. Therefore, use decodeURI () and decodeURIComponent () instead.
Instance
In this example, we will use escape () to encode the string and then use unescape () to decode it:
<script type="text/javascript">var test1="Visit W3School!"test1=escape(test1)document.write (test1 + "<br />")test1=unescape(test1)document.write(test1 + "<br />")</script>
Output:
Visit % 20W3School % 21
Visit W3School!
TIY
Unescape ()
The following describes the JavaScript String () function.
Definition and usage
The String () function converts the object value to a String.
Syntax
String (object)
Parameters |
Description |
Object |
Required. JavaScript Object. |
Instance
In this example, we will try to convert different objects into strings:
<script type="text/javascript">var test1= new Boolean(1);var test2= new Boolean(0);var test3= new Boolean(true);var test4= new Boolean(false);var test5= new Date();var test6= new String("999 888");var test7=12345;document.write(String(test1)+ "<br />");document.write(String(test2)+ "<br />");document.write(String(test3)+ "<br />");document.write(String(test4)+ "<br />");document.write(String(test5)+ "<br />");document.write(String(test6)+ "<br />");document.write(String(test7)+ "<br />");</script>
Output:
True
False
True
False
Wed Oct 28 00:17:40 UTC + 0800 2009
999 888
12345
The preceding section describes the functions of JavaScript SCAPE () and String () in JavaScript.