Skip to content

Latest commit

 

History

History
75 lines (62 loc) · 1.91 KB

File metadata and controls

75 lines (62 loc) · 1.91 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
return Statement (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
return_JavaScriptKeyword
JavaScript
TypeScript
DHTML
terminating execution
return statement
function statement
return statement, syntax
return statement, exiting functions in script
a9130d90-11fb-43f5-a819-7e5435f74c05
11
mikejo5000
mikejo
ghogen

return Statement (JavaScript)

Exits from the current function and returns a value from that function.

Syntax

  
return[(][expression][)];   

Remarks

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

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.

Example

The following example illustrates the use of the return statement.

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

Example

The following example illustrates the use of the return statement to return a function.

function doWork() {  
    return function calculate(y) { return y + 1; };  
}  
  
var func = doWork();  
var x = func(5);  
document.write(x);  
  
// Output: 6  

Requirements

[!INCLUDEjsv1]

See Also

function Statement