Javascript terminates the function from performing the action

  • 2020-03-30 01:46:03
  • OfStack

1. If a function is terminated with return, the example is as follows:
The function testA () {
      Alert (' a ');
      Alert (" b ");
      Alert (" c ");
}
TestA (); Program execution will pop up 'a','b','c'.

The function testA () {
      Alert (' a ');
      The return;
      Alert (" b ");
      Alert (" c ");
}
TestA (); Program execution will terminate when 'a' pops up.

The function testD () {
      TestC ();
      Alert (' d ');
}
TestD (); We see that testC is called in testD, and in testC we want to terminate testD with a return, and instead of that, the return just terminates testC, and the execution pops up 'c','d'.

The function testC () {
      Alert (" c ");
      Return false;
      Alert (" cc ");
}

The function testD () {
      If (! TestC return ());
      Alert (' d ');
}
TestD (); The two functions are modified, false is returned in testC, and the return value of testC is judged in testD, so that when testC is terminated, testD is also terminated, and the program execution pops out 'c' to terminate.


Related articles: