The Unescape () and string () functions in JavaScript are detailed in the following sections:
Definitions and usage
The JavaScript unescape () function decodes a string encoded by escape ().
Grammar
Unescape (String)
Parameters |
Description |
String |
Necessary. The string to decode or reverse. |
return value
A copy of a string that is decoded.
Description
This function works by finding a sequence of characters in the form%xx and%uxxxx (x represents a hexadecimal number), which is decoded by replacing such sequences with Unicode characters \u00xx and \uxxxx.
Tips and comments
Note: ECMAScript v3 has removed the unescape () function from the standard and objected to its use, so it should be replaced with decodeURI () and decodeURIComponent ().
Instance
In this case, we'll use escape () to encode the string and then decode it using unescape ():
<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 ()
Let me introduce you to the JavaScript String () function
Definitions and usage
The string () function converts the value of an object to a string.
Grammar
String (object)
Parameters |
Description |
Object |
Necessary. A JavaScript object. |
Instance
In this example, we will try to convert different objects to 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 00:17:40 utc+0800 2009
999 888
12345
These are the Unescape () and string () functions of the JavaScript described in the small series, I hope you like it.