About the abort instruction

In js, there are generally break, continue and return about termination instructions.
where break, county is the instruction used to terminate the loop. And return is the system used to terminate the function. They are explained below.
The break statement can be used in for loops and while loops to exit the loop early. E.g:
var number = [0,1,3,5,8,9,2,1,3,4,5,6,67,0];
for(var i=0;i<number.length;i++){
if(i==5)
break;
console.log(i);

}


Its output is 0, 1, 2, 3, 4. Exit this loop directly when i==5. Subsequent ones are not executed.
The continue statement is similar to the break statement. The difference is that instead of exiting a loop, it starts a new iteration of the loop. The continue statement can only be used in the loop body of a while statement, do/while statement, for statement, or for/in statement, and it will cause an error to use it in other places!
var number = [0,1,3,5,8,9,2,1,3,4,5,6,67,0];
for(var i=0;i<number.length;i++){
if(i==5)
continue;
console.log(i);

}



The result of his operation is 0, 1, 2, 3, 4
, 6, 7, 8, 9, 10, 11, 12, 13, so this statement exits this loop when i==5, and then continues the next loop . This is the difference with break.

The third return statement:

The return statement is used to specify the value returned by the function.

The scope of application of the return statement can only appear in the function body . Anywhere else in the code will cause a syntax error!

1. Return the control and function results. The

syntax is: return expression; the statement ends the function execution, returns the calling function, and uses the value of the expression as the result of the function. During the operation of the function, if the value is not revoked, it is a process with no results.

2. Return control,

no function result, the syntax is: return;

in most cases, returning false for the event handler can prevent the default event behavior. For example, by default, clicking an <a> element, the page will jump Go to the page specified by the href attribute of the element.  

Return False is equivalent to the terminator, and Return True is equivalent to the executor.  

The function of return false in js is generally used to cancel the default action. For example, when you click a link, in addition to triggering your  

onclick time (if you specify it), a default event is also triggered, which is to perform a page jump. So if  

you want to cancel the default action of the object you can return false.
function a(){

   if(True)

       return false;

}



The return statement is only valid within the current function. . . ! ! ! !






Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326984089&siteId=291194637