JavaScript Learning Notes (ii)

Source: Internet
Author: User

This time the main record is the type conversion in JavaScript and three encoding functions.

One, type conversion

Type conversions in JavaScript, which belong to global objects.

parseint (string); Converts a string to an integer parsefloat (string); To convert a string to a floating-point type

Number turns into String type:

Num.tostring (); num.tostring (2); Display Num.tostring (8) in binary form; num.tostring (16);

Two or three encoding functions (ref. W3school)

Encoding functions become URIs, a more important use is to ensure that some special characters can be in different places (such as client, server side) can be normal parsing.

1. encodeURI ();

Reference: http://www.w3school.com.cn/jsref/jsref_encodeuri.asp

A string can be encoded as a URI (a Universal Resource identifier).

Use: encodeURI (uristring), where certain characters are replaced by hexadecimal escape sequences.

The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ()
Such as:

document.write (encodeURI ("Http://www.w3school.com.cn/My first/"));

Output:
http://www.w3school.com.cn/My%20first/

 2. encodeURIComponent ();

Reference: http://www.w3school.com.cn/jsref/jsref_encodeURIComponent.asp
The string is encoded as a URI component.
The difference from encodeURI:
Such as:
document.write (encodeURIComponent ("http://www.w3school.com.cn/p 1/"));
Output: (Space is%20)
http%3a%2f%2fwww.w3school.com.cn%2fp%201%2f

3. Escape ();

  Reference: http://www.w3school.com.cn/jsref/jsref_escape.asp
Encoding a string allows the string to be read on all computers.
Such as:
document.write (Escape ("Visit w3school!");
Output:
Visit%20w3school%21

JavaScript Learning Notes (ii)

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.