1, SetTimeout
SetTimeout (function () {
}), 1000)
SetTimeout (function (num) {
Alert (num)//Bounce 123
},1000,123)
2. Stitching strings (using \)
Document.body.innerHTML = ' <div>div</div>\
<span>span</span>\
<p>p</p>\
55555 '
3. Console.log (in console output style%c)
var test = 123;
Console.log (test); Normal input Log text
Console.log ('%c ' +test, ' color:red;font-size:20px;background:blue ')//output text with style
4, typeof (to be called by the form of)
var test = 123;
typeof Test//number
typeof (Test)
Instanceof, in also have similar use method
5, nested for loop (jump out of the entire loop)
for (Var i=0;i<5;i++) {
for (Var j=0;j<1;j++) {
if (i==3) break;
Alert (i)
}
}
Result: 0,1,2,4, where 3 jumps out of the loop inside
Cc:for (var i=0;i<5;i++) {
for (Var j=0;j<1;j++) {
if (i==3) break cc;
Alert (i)
}
}
Results: 0,1,2
6, for (;;) parameter is not written is possible
for (Var i=0;i<5;i++) {
alert (i);
}
The rewrite of the no-write parameter is as follows:
var i=0;
for (;;) {
alert (i);
if (++i>=5) break;
}
7. Call
Call is used to change this point and, if not written, to indicate window Object
8, InsertBefore
if (!ali.length) {
First one
Oul.appendchild (OLi)
} else {
Oul.insertbefore (oli,ali[0])//If ali[0] is empty, then appendchild is one thing, so you can write directly: Oul.insertbefore (Oli,ali[0])
}
9, anonymous function self-execution (bitwise operators can also)
(function () {}) ()
~function () {} ()
!function () {} ()
+function () {} ()
10. Create objects (you can omit parentheses)
function Aaa () {}
var test = new Aaa ();
You can also var test = new Aaa;
System objects are also available:
var arr = new Array;
Do you really know JS?