JavaScript Global method

Source: Internet
Author: User

1. encodeURI (URI)

A, the role: is the Uniform Resource Identifier (URI) encoding method;

B, Parameter: is a complete URI;

C. Features: No need to encode reserved words and characters that have special meaning in the URI.

(1), reserved characters: ; , / ? : @ & = + $

    (2), non-escape character: alphanumeric - _ . ! ~ * ( )

(3), Mathematical symbols: #

2, decodeURI (Encodeduri)

A, role: decoding a Uniform Resource Identifier (URI) encoded by encodeURI or a similar method;

B, Parameters: a fully encoded URI;

c. Features: converts all the escaped sequences in the encoded URI to the original characters, but does not decode content that is not encoded by encodeURI (for example, "#").

3, encodeURIComponent (str)

A, the role: is the Uniform Resource Identifier (URI) component encoding method;

B, Parameters: String.uri components;

C, feature: Escape all characters except letters, numbers, (,) 、.、!、 ~, *, ',-and _.

4, decodeURIComponent (Encodeduri)

A, role: decoding a Uniform Resource Identifier (URI) encoded by encodeuricomponent or a similar method;

B, Parameters: Part of the URI after encoding;

C. Feature: Converts all the escaped sequences in the encoded URI to the original characters.

5. Eval (str)

A, the role: the incoming string as JavaScript execution;

B, Parameters: strings, expressions that need to be evaluated, or statements executed;

C, return value: Code after the execution of the return value, otherwise undefined;

D, Features: (1), if the parameter is not a string, returned unchanged, (2), direct invocation, using the current scope, indirect invocation, using the global scope.

Eval (new//  Returns a String object containing "2 + 2" //  returns 4function  test () {     var x = 2, y = 4;    Console.log (eval ("x + y"));  // called directly, using the local scope, the result is 6    var geval = eval;    Console.log (Geval (//  Indirect call, using global scope, throws Referenceerror because ' x ' is undefined}

6, Isfinite (testval): Similar to Number.isfinite (TestVal)

A, function: Judge whether the TestVal is a finite value;

B, Parameter: Incoming string, will be converted into a number to judge. Note: number.isfinite (testval) does not convert the type.

C, return value: True/false;

Isfinite (Infinity);//falseIsfinite (-infinity);//falseIsfinite (0);//trueIsfinite (2E64);//trueIsfinite ("0");//trueIsfinite (NaN);//falseIsfinite (NULL);//trueIsfinite (undefined);//falseIsfinite (true);//trueIsfinite (false);//trueNumber.isfinite (Infinity); //falseNumber.isfinite (-infinity);//falseNumber.isfinite (0);//trueNumber.isfinite (2E64);//trueNumber.isfinite ("0");//falseNumber.isfinite (NaN);//falseNumber.isfinite (NULL);//falseNumber.isfinite (undefined);//falseNumber.isfinite (true);//falseNumber.isfinite (false);//false

7, IsNaN (TestVal)

A, the role: Determine whether a value is Nan, the argument is cast to a number and then judged.

B, return value: True/false

C, Characteristics: (1), Nan can not be determined by = = and = = =, Nan = = nan and Nan = = = Nan all return False, (2), arithmetic operations get a value that cannot be represented or undefined, is Nan, (3), cannot force a newline into a number, is Nan; (4), 0 divided by 0 will return nan--but the other number divided by 0 will not return Nan.

Escape (), unescape (): Abandoned.

D, Note: It is a reliable practice to detect whether a variable x is a non-numeric value by Number.isnan (x). However, in the absence of the Number.isnan function, it is more reliable to detect if the variable x is Nan by means of an expression (x! = x).

IsNaN =function(value) {Number.isnan (number);}       IsNaN (NaN); //trueIsNaN (undefined);//trueIsNaN ({});//trueIsNaN (0/0);//trueIsNaN (5/0);//falseIsNaN (true);//falseIsNaN (NULL);//falseIsNaN (37);//falseIsNaN ("37");//false: Can be converted to a number of PNSIsNaN ("37.37");//false: Can be converted to numeric 37.37IsNaN ("");//false: An empty string is converted to 0IsNaN ("");//false: A string containing spaces is converted to 0IsNaN (NewDate ());//falseIsNaN (NewDate (). toString ());//trueIsNaN ("BlaBla")//true: "BlaBla" cannot be converted to a numeric value//compared to the global function IsNaN (), this method does not force the parameter to be converted to a number, and returns true only if the parameter is a true numeric type and the value is NaN. Number.isnan (NaN);//trueNumber.isnan (undefined);//falseNumber.isnan ({});//falseNumber.isnan (0/0);//trueNumber.isnan (5/0);//falseNumber.isnan (true);//falseNumber.isnan (NULL);//falseNumber.isnan (37);//falseNumber.isnan ("37");//false: cannot be converted to a value of PNsNumber.isnan ("37.37");//false: cannot be converted to numeric 37.37Number.isnan ("");//false: No empty string is converted to 0Number.isnan ("");//false: Strings that do not contain spaces are converted to 0Number.isnan (NewDate ());//falseNumber.isnan (NewDate (). toString ());//falseNumber.isnan ("BlaBla")//false: "BlaBla" cannot be converted to a numeric value

8, null and undefined

A, null:javascript literal, one of the original JavaScript values, representing the null value, not the property of the global object

B, Undefined:javascript one of the original values, is the raw data type of JavaScript, is the property of the global object

typeof NULL        //object (because of some previous reason rather than ' null ')typeofUndefined//undefinedNULL= = = undefined//falseNULL= = undefined//trueNULL===NULL //trueNULL==NULL //true!NULL //trueIsNaN (1 +NULL)//falseIsNaN (1 + undefined)//true

9, parseint and parsefloat

A, parseint: Returns an integer

B, parsefloat: Returns a floating-point number

JavaScript Global method

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.