JavaScript tutorial:
return statement

 

The return statement exits from the current function and returns a value from that function.

Syntax

return [expression];

The expression argument is the value to be returned from the function. If omitted, the function does not return a value.

Return value

The return statement returns the value accoding to that function.

Example

You use the return statement to stop execution of a function and return the value of expression. If expression is omitted, or no return statement is executed from within the function, the expression that called the current function is assigned the value undefined.

The following example illustrates the use of the return statement:

function multiply(arg1, arg2)
{
    var r;
    r = arg1 * arg2;
    return(r);
}

document.write(multiply("5","6"));

To run the code, paste it into JavaScript Editor, and click the Execute button.

See also: function statement