Simple Description of JavaScript global functions-Basic Knowledge-js tutorial

Source: Internet
Author: User
Some common character processing functions in JavaScript are often used by friends who learn JavaScript. 1. decodeURI () parameter: string

Function Description: decode the URI encoded by the encodeURI () function.

Instance:

Decodes a http://www.jb51.net/My%20first/ to a http://www.jb51.net/My first/

2. decodeURIComponent () parameter: string

Function Description: decodes the URI encoded by the encodeURIComponent () function.

3. encodeURI () parameter: string

Function Description: encode a string as a URI.

Tip: If the URI component contains a separator, such? And #, use the encodeURIComponent () method to encode each component.


4. encodeURIComponent ()

Function Description: encode a string as a URI component.

Note the differences between the encodeURIComponent () function and the encodeURI () function. The former assumes that its parameters are part of the URI (such as the protocol, host name, path, or query string ).

Therefore, the encodeURIComponent () function uses escape characters to separate the punctuation marks of each part of the URI.

5. escape () parameter: string

Function Description: encode a string so that the string can be read on all computers. This method does not encode ASCII letters and numbers,

The following ASCII punctuation marks are not encoded :-_.! ~ *'(). All other characters are replaced by escape sequences.

Tip: ECMAScript v3 rejects this method. The application uses decodeURI () and decodeURIComponent () to replace it.

6. unescape () parameter: string

Function Description: decodes a string encoded using escape. 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.

Tip: ECMAScript v3 has deleted the unescape () function from the standard and opposed it. Therefore, use decodeURI () and decodeURIComponent () instead.

7. eval () parameter: string

Function Description: computes a string and executes the JavaScript code.

Instance:

Document. write (eval ("12 + 2") will output 14
Note: The parameter must be of the string type, otherwise the method will be returned without any change.
8. isFinite () parameter: number
Function Description: used to check whether the parameters are large or small. If number is a finite number (or can be converted to a finite number ),
Returns true. Otherwise, if number is NaN (not a number) or positive or negative infinity, false is returned.
Instance:
IsFinite (-125) and isFinite (1.2) return true,
While isFinite ('yishuihan') and isFinite ('2017-3-11 ') return false.
9. isNaN () parameter: Unlimited
Function Description: checks whether a parameter is a non-numeric value.
Instance:
IsNaN (123) and isNaN (0) return false
IsNaN ("Yi Shui Han") and isNaN ("100") return true.
Note: The isNaN () function can be used to detect arithmetic errors. For example, if 0 is used as the divisor.
10. Number () parameter: Unlimited
Function Description: converts an object value to a number. If the parameter is a Date object, Number () returns the Number of milliseconds since January 1, January 1, 1970. If the object value cannot be converted to a Number, the Number () function returns NaN. Instance:
Var test1 = new Boolean (true );
Var test2 = new Boolean (false );
Var test3 = new Date ();
Var test4 = new String ("999 ");
Var test5 = new String ("999 888 ");

Document. write (Number (test1); Output 1
Document. write (Number (test2); Output 0
Document. write (Number (test3); 1256657776588 output
Document. write (Number (test4); 999 output
Document. write (Number (test5); Output NaN
And
ParseFloat () parseInt () String!
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.