You think you know a lot about javascript? (Personal answer)

Source: Internet
Author: User

Code Source:http://www.ido321.com/914.html

Code Source:http://dmitry.baranovskiy.com/post/91403200

Pure personal understanding, Welcome to the Great God,

1.

1     if inch window)) {23         var a = 1; 4 5     }67     alert (a);  // undefined

There is no block-level scope in JS, so a will declare in advance that "a" in window will get true, so a is not assigned a value operation

2.

1     var a = 1,23         function  A (x) {45             x && A (--x); 6 7         }; 8 9     // 1

First, refer to the following code

1 var function g () {2// eject G's function body 3}; 4 alert (g);  // will error, G is not undefined

G works only in its function body.

So b=function A (x) {...} Does not affect the global variable A,

3.

1     function A (x) {23         return x * 2; 4 5     }67     var  A; 8 9     // Popup function Body

There seems to be no suspense, the function declaration executes before any statement, and the seventh line simply re-declares a, but does not make any changes to a.

1     var fn = 1; 2     function fn () {3         alert ("FN"); 4     }5     alert (FN);   1

If the FN is re-assigned, it will change the FN, the function declaration and function expression of the contents can refer to Uncle Tom's detailed explanation (http://www.cnblogs.com/TomXu/archive/2011/12/29/2290308.html)

4.

1             function B (x,y,a) {2                 arguments[2]=10; 3                  45                         //

In fact, in the function body, a and arguments[2] are references to the same parameter, as follows:

1     function fn (v) {2         alert (arguments[0]===3    }4     //  True

However, if you manually modify V or arguments in the function body when the passed parameter value is empty, it will result in no longer a reference to the same object

1             functionfn (v) {2                 //do not make any changes to V and arguments3Alert (v = = = Arguments[0]);//true4                 5                 6v = 10;7Alert (v);//Ten8Alert (arguments[0]);//undefined9alert (ARGUMENTS[0]===V);//falseTen                  One                 /* A arguments[0]=10; - alert (arguments[0]);//10 - alert (v);//undefined the alert (arguments[0]===v);//false*/ -             } -FN ();

5.

1     function A () {23         alert (this); 4 5     }67     a.call (null);

The syntax for call in JavaScript is call (Thisobj,arg1,..., argn)
Parameter thisobj: An option that will be used as the object of the current object.
Parameter arg1,..., argn: Optional, the method parameter sequence is passed.

If no thisobj is empty, the call is made by default with global (window):

1             functionfn () {2Alert This);3             }4Fn.call (NULL);//[Object window]5Fn.call ();//[Object window]6Fn.call (undefined);//[Object window]7Fn.call (window);//[Object window]

You think you know a lot about javascript? (Personal answer)

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.