Do you really know JS?

Source: Internet
Author: User

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?

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.