JS Return - ashish9342/FreeCodeCamp GitHub Wiki

JavaScript Return

Introduction

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

Examples

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

function square(x) {
   return x * x;
}

🚀 Run Code

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

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

🚀 Run Code

⚠️ **GitHub.com Fallback** ⚠️