The return statement exits from the current function and returns a value from that function.
Grammar:
1 |
return [()[expression][]]; |
The optional expression argument is the value to be returned from the function. If omitted, the function does not return a value. Xiping County Quine Friends Electric
Use the return statement to terminate the execution of a function and return the value of expression. If expression is omitted, or if no return statement is executed within the function, the value undefined is assigned to the expression that invokes the current function.
The following example illustrates the use of the return statement:
1 |
function myfunction(arg1, arg2){ |
Return indicates that the function returned from the callback to the key function continues execution, which can be returned with a return value specified by the argument following return. Return is usually necessary because the result of a function call is usually taken out of the return value.
If you really do not need a function to return what value, you need to declare its type with void.
Add: If you have a return type definition in front of a function name, such as int,double, you must have a return value, and if it is void, you may not write return, but you cannot return a value even if it is written:
The following is a non-void function:
function of void type:
View Source print?
4 |
//return;//这样也可以,不要这一句也可以 |
Use of the JavaScript keyword return