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