Round down:


To supplement this, you can use the bit right shift character >>


But it’s best to use both on positive integers only, because you’re just canceling out the decimals. Math.floor(-1.2) should be -2, and the result for both methods is -1

Turn to digital


Set the default value


function foo(bar){ var foobar = bar || 'default'; / / bar is undefined, null, ", "0, false, NaN when finally get 'default'} [] / / pit | |" aa ". //[] {}||"aa"; //SyntaxError ({})||"aa"; //Object {}Copy the code


The pit of NaN


//NaN - is not a number isNaN(a); // Check if "not a number".. isNaN(null); //false // null is converted to 0, null is not a non-number thing. wtf...Copy the code


UNICODE is used as the variable name


var \u4f60\u597d = "\u4f60\u597d"; var b = {}; b.\u4f60\u597d = \u4f60\u597d; console.log(b); //Object {hello: "hello "} console.log(b). Hello); // "Hello" console.log(b.u4f60 \u597d); // "hello" console.log(" you "==="\u4f60"); //trueCopy the code


Array passing and copying


Var a = [1, 2, 3]; var b = a; delete b[1]; console.log(a); // undefined * 1, 3] var a = [4,5,6]; var b = a.slice(0); delete b[1]; console.log(a); / / (4 and 6) the console. The log (b); / / [4, undefined x 1, 6]Copy the code


Object and the Function


console.log(typeof Function); //"function" console.log(typeof Object); //"function"Copy the code


Function declaration


aa(); function aa(){return true; } //true bb(); var bb = function(){return true; } //TypeErrorCopy the code


toString()


2.toString(); //SyntaxError 2 .toString(); / / "2" 2.. toString(); //"2" (2).toString(); //"2" [1,[2,"abc","",0,null,undefined,false,NaN],3].toString(); / / "1, 2, ABC, and 0,,, false, NaN, 3"Copy the code


For in exposes the stereotype chain property


Object.prototype.foo = 1; var obj = new Object(); obj.bar = 1; for(var p in obj){ console.log(p); //bar,foo are all iterated. You can use hasOwnProperty() to filter prototype chain properties}Copy the code


Switch instead of if else


 switch (true) {  
        case (a > 10):  
            do_something();
            break;
        case (a < 100):  
            others();  
            break;  
        default:
            ;  
            break;  
    };  
Copy the code


There is too much…