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 executes, returns the calling function, and takes the value of the expression as the result of the function

Second, return control

No function result, the syntax is: return;

In most cases, false is returned for the event handler to prevent the default event behavior. For example, by clicking on a <a> element by default, the page jumps to the page specified by the href attribute of the element.

return false; is equivalent to a terminator,

return true; Just want to be the executor.

In JS, the function of return false is generally used to cancel the default action. For example, if you click a link to trigger a default event other than triggering your onclick event (if you specify it), the jump to the page is performed. So if you want to cancel the object's default action, you can return false.

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

function A () {

if (true)

return false;

}

There's nothing wrong with that.

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, and return false inside a () 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.

Retrun false; Returns the processing result of the error, terminating processing.

Retrun; return control to the page.

Source: http://www.cnblogs.com/weiwang/archive/2013/08/19/3268374.html

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.