Home > Web Front-end > JS Tutorial > How to stop execution of javascript

How to stop execution of javascript

藏色散人
Release: 2021-10-18 11:14:42
Original
12618 people have browsed it

How to stop execution of javascript: 1. Open the corresponding js code file; 2. Terminate function execution through the return method, code such as "function testA(){alert('a');return;alert( 'b');}".

How to stop execution of javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer

How to stop the execution of javascript?

javascript Terminate function execution operation

1. If you want to terminate a function, just use return. The example is as follows:

function testA(){
    alert('a');
    alert('b');
    alert('c');
}
Copy after login

testA(); When the program is executed, 'a', 'b', and '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. When calling other functions within a function, when the called function terminates, the calling function is also expected to terminate. The example is as follows:

function testC(){
    alert('c');
    return;
    alert('cc');
}
function testD(){
    testC();
    alert('d');
}
Copy after login

testD(); We see that in testD TestC was called. In testC, I wanted to terminate testD through return. However, contrary to expectations, return only terminated 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 'c' pops up when the program is executed. will terminate.

Recommended study: "javascript basic tutorial"

The above is the detailed content of How to stop execution of javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template