return Statement

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

语法

return[(][expression][)];

备注

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.

示例

The following example illustrates the use of the return statement.

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

示例

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

必备条件

在以下文档模式中受支持:怪异模式、Internet Explorer 6标准模式、Internet Explorer 7标准模式、Internet Explorer 8标准模式、Internet Explorer 9标准模式、Internet Explorer 10标准模式、Internet Explorer 11标准模式。应用商店应用(Windows 8和Windows Phone 8.1)中也受支持。请参阅版本信息

如果你喜欢这篇文章,敬请给站长打赏↑

除特别注明外,本站所有文章均为本站站长原译,转载请注明出处。