JavaScript's understanding of semantic functions

Source: Internet
Author: User

See code Example 1

        varA=1; functionM (a) {//here is the parameter of the first incoming function of the formal parameter, both arguments[0]alert (a);//where a is bound to a formal parameter} m (a);//1 A In this case passes the variable a as a parameter to the function.......................................................................................................        varA=1; functionm (a) {alert (a); } m ();//Undefind is bound to a function as null because there are no parameters passed in, so alert a undefined

code Example 2

 var  a=1;  function  m () {//              alert (a);        alert (b);  function   n () { var  a=5;  var  b=3; //         m (); } n ();  //  alert A is 1, to the B-times wrong is not defined  m (); //  alert A is 1, to the B-times wrong is not defined  

The visible function m, when created, has bound itself to the scope of the creation environment, where it is a global scope, and when called in function N, it does not look for a variable in the private scope of function n, so the function n defines

A and B do not appear in the scope chain of the function m, as shown in the comments in the code.

code example 3

      var a=1;         function   m (a) {///A In this case and a in the function are formal parameters and have no relation to the a variable declared in the first line, they have no binding relationship in Instance 2            alert (a);        }         function N () {            var a=5;//             M (a);//The variable A is passed into function m, and when alert A is required, the value of a is alert,        }        N (); // 5        M (); // Undefind

Here the difference is due to the differentiated participation variable.

The scope of the anonymous function is more complex, wait for a good sleep and then get up and tidy up.

JavaScript's understanding of semantic functions

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.