function inside the function is called the closure of the function: the child function can call the parent function variable, if the child function cannot find the variable, then the entire scope chain of variables will be saved

Source: Internet
Author: User

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">5 <title>Untitled Document</title>6 <Script>7     //Scope8     vara=0;9     Ten     functionABC () { One         vara=1; A alert (a); -         functionC () { - alert (a); the         } - C () -     } -       + ABC () -     //alert (a) + //alert (a); A </Script> at </Head> -  - <Body> - </Body> - </HTML>

Results: Two times a=1 was popped;

Explanation: First executes the function ABC (), A=1 is the local variable inside, takes precedence over the global variable, so the first time alert result is ABC's 1;

Then execute the function C (), Functions C is a sub-function of ABC, and function C does not have a variable, so it will go to his parent, that is, the variable var a=1 abc, then the C pop-up is also 1.

function inside the function is called the closure of the function: the child function can call the parent function variable, if the child function cannot find the variable, then the entire scope chain of variables will be saved

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.