Brief introduction to return statements in JavaScript _ javascript skills

Source: Internet
Author: User
The return statement plays an important role in js. This keyword not only has the function of returning the function, but also has some special usage. it is necessary to have a clear grasp of it, next, we will use this article to briefly introduce the role of the return statement in js. it not only has the function of returning the function value, but also has some special usage, the following describes the functions of the return statement based on the instance.

1. return control and function results:

Generally, the return statement is necessary for a function, because it usually requires the function to get an expected return value after a series of code execution, and this value is returned through the return statement, and return the control to the main function.

Syntax format:

Return expression

The code example is as follows:

function add(){ var a=1; var b=2; return a+b;}function func(){ console.log(add())}func(); 

In the above code, when the func () function is called, the control is controlled by the func function. when the add function is called again, the control is delivered to the add function, return a value and pay the control to the func function.

Usually return is followed by an expression, but it is not absolute. for example:

Return;

In this case, control is simply transferred to the main function for further execution.

Extension description:

The common application of return statements has no special features. The most important thing to note is the use of return false. The event handler function returns false to organize the occurrence of default events.

The code example is as follows:

   
  
  Foot home 

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.