Home > Web Front-end > JS Tutorial > body text

Detailed explanation of Unescape() and String() functions in JavaScript_javascript skills

WBOY
Release: 2016-05-16 15:33:14
Original
1394 people have browsed it

Detailed explanation of Unescape() and String() functions in JavaScript, the specific content is as follows:

Definition and usage

The JavaScript unescape() function can decode strings encoded by escape().

Grammar

unescape(string)

参数 描述
string 必需。要解码或反转义的字符串。

Return value

A decoded copy of string.

Description

This function works by decoding by finding character sequences of the form %xx and %uxxxx (x represents a hexadecimal number) and replacing such character sequences with the Unicode characters u00xx and uxxxx.

Tips and Notes

Note: ECMAScript v3 has removed the unescape() function from the standard and deprecated its use, so it should be replaced by decodeURI() and decodeURIComponent().

Example

In this example we will use escape() to encode the string and then 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>
Copy after login

Output:

Visit W3School!
Visit W3School!
TIY
unescape()

Let me introduce to you the JavaScript String() function

Definition and usage

String() function converts the value of the object into a string.

Grammar

String(object)

参数 描述
object 必需。JavaScript 对象。

Example

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>
Copy after login

Output:

true
false
true
false
Wed Oct 28 00:17:40 UTC 0800 2009
999 888
12345

The above is the unescape() and String() functions in JavaScript introduced by the editor. I hope you like it.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!