Terminate function execution in javascript
This article mainly introduces how to terminate function execution in javascript. If you need it, you can refer to it for help.
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.