JS You may not know some of the points of knowledge (i)

Source: Internet
Author: User

1, JS program is written in the Unicode character set,

2. Escape character: Backslash

function Test () {   var s= ' you\ ' re right,it can\ ' t be a quote ';   Console.log (s);}

3. Slice method: Method to return the selected element from an existing array arrayobject.slice (Start,end)

Start required if it is a negative number, it specifies the position from the end of the array. In other words, 1 refers to the last element, 2 refers to the second-lowest element, and so on.
End optional specifies where to end the selection

function Test () {    var arr = new Array (3);    Arr[0] = "George";    ARR[1] = "John";    ARR[2] = "Thomas";    ARR[3] = "James";    ARR[4] = "Adrew";    ARR[5] = "Martin";    var s= "Hello World";    document.write (Arr.slice (1) + "<br/>")    document.write (Arr.slice (2, 4) + "<br/>")    document.write (S.slice (1, 4) + "<br/>")    document.write (S.slice ( -3) + "<br/>")}

Results:

John,thomas,james,adrew,martin
Thomas,james
Ell
Rld

4. The original value of JS species (Undefined,null, Boolean, number, string)

function Test () {    var s = "Test";    var s1= "test";    if (S===S1) {}//true}

Reference type: Object, array

function Test () {   var o={x:1};   var p={x:1};   if (o===p) {}//false   var a=[1,2,3];   var b=[1,2,3];   if (a===b) {};//false   var c=[];   var d=c;   B[0]=1;   if (C==d) {};//true}

5. Type conversion

   Boolean   //undefined-> "undefined"->nan->false   //null-> "null"->0- >false   //true-> "true"->1->true   //false-> "false"->0->false   //"" (empty string), "->0->flase   //" 1.2 "(non-empty, digital)," 1.2 "   ->1.2->true//" One "(non-null, non-digital)," one "->nan-> True   //0-> "0"->0->false   //nan-> "NaN"->nan->flase   //1-> "1"->1->true

6. Operators

1) in operator

function Test () {     var o={x:1,y:2};    The left is a string or can be converted to a string, the right is an object, the left property exists on the right side of the object, then return OK if ("    x" in O) {}//true if ("    z" in O) {}//false if ("    toString" in O {}//true, object inherits the ToString method}

2) instanceof

    var d=new Data ();    if (d instanceof date) {}//true The Left object is an instance of the right class, returns True    if (z instanceof date) {}//false

3) Delete

function Test () {     var o={x:1,y:2};    Delete o.x;    if ("X" in O) {}//false}

7. For in

function Test () {     var o={x:1,y:2};    For (i in O) {        console.log (o[i]);}    }

8. Try: Catch.. Finally

function Test () {     try{        var n=number (Prompt ("Please enter a positive integer"));        var f=factorial (n);        Alert (n+ "! =" +f);    }    catch (ex) {        alert (ex);    }    finally{        Aler ("show" whether or not there is an exception);    }}function factorial (x) {     if (x<0) {        throw new Error ("X cannot be negative");    }    if (IsNaN (x)) {        throw new Error ("You are not entering a number");    }    for (Var f=1;x>1;x--) {        f*=x;    }    return F; }

9. Width statement

function Test () {    //Document.forms[0].username.value = "AA";    Document.forms[0].pwd.value = "AA";    Document.forms[0].qq.value = "AA";    Document.forms[0].realname.value = "AA";    Document.forms[0].tel.value = "AA";    Simplified mode with    (Document.forms[0]) {        username.value= "AA";        Pwd.value= "AA";        Qq.value= "AA";        Tel.value= "AA";        Realname.value= "AA";    }}

  

 

  

JS You may not know some of the points of knowledge (i)

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.