What is the difference between return and return()?

后端 未结 9 1452
误落风尘
误落风尘 2020-12-13 16:37
function a() { return 1; }
function b() { return(1); }

I tested the above code in Chrome\'s console, and both returned 1.



        
9条回答
  •  一整个雨季
    2020-12-13 17:23

    There is no difference, the parenthesis are optional. See MSDN:

    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.

提交回复
热议问题