Terminate function execution in javascript

Source: Internet
Author: User

1. if return is used to terminate a function, the instance is as follows:
Function testA (){
Alert ('A ');
Alert ('B ');
Alert ('C ');
}
TestA (); program execution will pop up 'A', 'B', 'C' in sequence '.

Function testA (){
Alert ('A ');
Return;
Alert ('B ');
Alert ('C ');
}
TestA (); when the program execution pops up, 'A' will be terminated.

2. Call other functions in the function. If the called function is terminated, the function to be called is terminated. The example is as follows:
Function testC (){
Alert ('C ');
Return;
Alert ('cc ');
}

Function testD (){
TestC ();
Alert ('D ');
}
TestD (); we can see that testC is called in testD. In testC, we want to terminate testD through return. If yes, return only terminates testC, 'C' and 'D' will pop up in sequence during program execution '.

Function testC (){
Alert ('C ');
Return false;
Alert ('cc ');
}

Function testD (){
If (! TestC () return;
Alert ('D ');
}
TestD (); the two functions have been modified. In testC, false is returned. In testD, testC's return value is judged. In this way, testC can be terminated while testD is terminated, if 'C' is displayed during program execution, it is terminated.

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.