Explain the functions of Unescape () and String () in JavaScript, and explain criptunescape

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.