The JavaScript Return Statement

The JavaScript Return Statement
0.0 0



When a return statement is called in a function, the execution of this function is stopped. If specified, a given value is returned to the function caller. If the expression is omitted, undefined is returned instead.

return [[expression]];

MDN link | MSDN link


The following function returns the square of its argument, x, where x is a number.

function square(x) {
   return x * x;

:rocket: Run Code

The following function returns the product of its arguments, arg1 and arg2.

function myfunction(arg1, arg2){
   var r;
   r = arg1 * arg2;

:rocket: Run Code