Analysis of javascript return Statement _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces the return Statement of javascript. The return statement is very important in js. It not only has the function of returning function values, but also has some special usage, interested friends can refer to the javascript return statement for a brief introduction:
Return statements are very important in js. They not only have the function of returning function values, but also have some special usage. It is necessary to have a clear grasp of them. 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:

   
  
  Ant tribe 
Related Article

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.