What is the difference between return and return()?

后端 未结 9 1455
误落风尘
误落风尘 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:31

    The same as between

    var i = 1 + 1;
    

    and

    var i = (1 + 1);
    

    That is, nothing. The parentheses are allowed because they are allowed in any expression to influence evaluation order, but in your examples they're just superfluous.

    return is not a function, but a statement. It is syntactically similar to other simple control flow statements like break and continue that don't use parentheses either.

提交回复
热议问题