JS in return, return false, return true what each means

Source: Internet
Author: User

The return statement represents the need to return a value, and you do not need to use the return statement if you do not need it. are similar to an exit, return can end the execution of part of the code in the body of the method after return. return False or return true is commonly used to determine some results.

Return:1. Return control with function result that is return + expression, call function, and return the value of the expression

2. Return control, no function value or return. Is the function does not need to return the value, when you need to abort the function down, use this

In most cases, the function undergoes a series of operations, and there is a return value, which is returned to the external need, which is usually returned, that is, return is the returning value, not the terminating function. But note: return expression; The code after this function is no longer running.

For example: function onclick () {

/* **/in arithmetic

return expression;

/* Other code */==>> not executed


Return false.:1. Usually let the function return false is to prevent the default default event from occurring (that is, continue executing the following code) when a certain condition is not met or met, but note that return false is valid only in the current function and does not affect the execution of other external functions.

2. Return Error processing results

3. Termination of processing.

4. Block the submission form (onsubmit= "return false";).

For example:

<ul id= "Imglib" >
<li><a href= "Img/1.png" title= "Santa 1" onclick= "showpic (this); return false" > Santa Claus </a></li>
<li><a href= "img/3.png" title= "singular Tower 1" onclick= "showpic (this); return false" > singular tower </a></li>
<li><a href= "Img/4.png" title= "Robot 1" onclick= "showpic (this); return false" > Robot </a></li>
Clicking the hyperlink <a>, does not open the page that jumps to the href, but just runs the show () function. That prevents the default event from occurring.

Return true: Returns the normal result of the processing, if this is used to return the following code to terminate.

JS in return, return false, return true what each means

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.