JS in return, return true, return false;

Source: Internet
Author: User

First, return control and function results,
The syntax is: return expression, statement End Function execution, return call function, and the value of the expression as the result of the function
Second, return control,
No function result, the syntax is: return;





You can return FALSE if you want to cancel the object's default action.

First in JS, we often use return false to prevent the submission of the form or the person continues to execute the following code, in general, to prevent the execution of the default behavior.

function A () {

if (True)
return false;
}, there is no problem with this.

If I change into this

function Test () {

A ();

b ();

C ();

}

Even if the a function returns false to prevent the commit, it does not affect the execution of the B () and C () functions. Call the A () function in the test () function.

Return false is equivalent to the return value for the test () function. The test () function cannot be prevented from executing.

In summary: Return false is valid only in the current function and does not affect the execution of other external functions.

Three: summary

Retrun true; Returns the correct processing result.

return false; Branch error processing result, terminate processing.

return; Returns control to the page.

JS in return, return true, return false;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.