JavaScript global functions

Source: Internet
Author: User

JS global function

1. decodeURI () parameter: string

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

Instance:

The Http://www.jb51.net/My%20first/can be decoded to Http://www.jb51.net/My first/

2. decodeuricomponent () parameter: string

function description: The function can decode the URI encoded by the encodeURIComponent () Function.

3. encodeURI () parameter: string

function description: The string can be encoded as a URI.

Tip: If the URI component contains delimiters, such as? and #, each component should be encoded using the encodeURIComponent () method.


4, encodeURIComponent ()

function description: The string can be encoded as a URI Component.

Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of a URI (such as a protocol, hostname, path, or query string).

therefore, the encodeuricomponent () function escapes punctuation marks that are used to separate the various portions of the URI.

5. Escape () Parameter: String

function description: A string can be encoded so that it can be read on all Computers. The method does not encode ASCII letters and numbers,

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

Warm tip: ECMAScript v3 against using this method, the app uses decodeURI () and decodeuricomponent () to replace it.

6. unescape () Parameter: string

function description: A string encoded by escape () can be decoded. The function works like This: by finding a sequence of characters in the Form%xx and%uxxxx (x is the hexadecimal number),

Use Unicode characters \u00xx and \uxxxx to replace such sequences of characters for Decoding.

Warm tip: ECMAScript v3 has removed the unescape () function from the standard and opposes its use, so it should be replaced with decodeURI () and decodeURIComponent ().

7. Eval () parameter: string

function description: you can calculate a string and execute the JavaScript code in it.

Instance:

document.write (eval ("12+2")) Outputs 14
Note: The parameter must be of type string, otherwise the method will return without any Change.
8. Isfinite () parameter: number
function description: used to check whether its parameters are Poor. If number is finite (or convertible to a finite number),
Then return True. otherwise, If number is NaN (not a number), or positive, negative infinity, then false is Returned.
Instance:
Isfinite (-125) and Isfinite (1.2) return true,
and isfinite (' easy water cold ') and isfinite (' 2011-3-11 ') return false.
9. IsNaN () Parameter: No Limit
function description: The function is used to check whether its arguments are non-numeric values.
Instance:
IsNaN (123) and IsNaN (0) return False
IsNaN ("easy Water Cold") and IsNaN ("100") return True.
Note: You can use the IsNaN () function to detect arithmetic errors, such as the case of dividing by 0.
10. Number () Parameter: No Limit
Function Description: Converts the value of an object to a number. If the parameter is a Date object, number () returns the milliseconds from January 1, 1970 to the Present. The number () function returns NaN if the value of the object cannot be converted to Numbers. 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)); Output 1256657776588
document.write (number (test4)); Output 999
document.write (number (test5)); Output NaN

11.parseInt (string,radix): returns the value converted to an integer.

Note: when the value of the parameter radix is 0, or the parameter is not set, parseint () determines the cardinality of the number based on String.

When you omit the Radix,javascript default number, the cardinality rule is:

1. If string starts with 0x, parseint () resolves the remainder of the string to a 16-binary integer.

2. If string starts with 0, then ECMAScript V3 allows an implementation of parseint () to parse subsequent characters into octal or hexadecimal digits.

3. If string starts with a 1~9 number, parseint () parses it into a decimal integer.

4. If the string starts with a valid character, parseint () intercepts the legal characters.

The opening and closing spaces of 5.String are Allowed.

6. If the first character of a string cannot be converted to a number, parseint () returns Nan.

7. The old browser uses the octal cardinality by default when the string starts with "0". ECMAScript 5, The default is the decimal base.

12.parseFloat (string): returns the value converted to a floating-point type.

The function specifies whether the first character in a string is a number. If it is, the string is parsed until the end of the number is reached, and then the number is returned as a number, not as a string.

13.String (): Converts the value of an object to a string

The string () function returns the same as the ToString () method value of the string object

JavaScript global functions

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.