1. If you want to terminate a function, just use return. The example is as follows:
function testA(){
alert('a');
alert('b');
alert ('c');
}
testA(); When the program is executed, 'a', 'b', 'c' will pop up in sequence.
function testA(){
alert('a');
return;
alert('b');
alert( 'c');
}
testA(); Program execution will terminate when 'a' pops up.
2. Call other functions within a function. When the called function terminates, you also want the calling function to terminate. The example is as follows:
function testC(){
alert('c');
return;
alert('cc');
}
function testD(){
testC();
alert('d');
}
testD(); We see that testC is called in testD, and think in testC TestD is also terminated through return. Contrary to expectations, return only terminates testC. When the program is executed, 'c' and 'd' will pop up in sequence.
function testC(){
alert('c');
return false;
alert('cc');
}
function testD(){
if(!testC()) return;
alert('d');
}
testD (); The two functions have been modified. TestC returns false, and testD judges the return value of testC. In this way, when testC is terminated, testD can also be terminated, and the program execution will terminate when 'c' pops up.