What is the difference between return and return()?

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

    There is absolutely no difference. If you will look at JS (ECMAScript) specification of return statement. Among many other things, it is telling you :

    return [no LineTerminator here] Expression ;

    that you can provide expression to return. Expression is hello, Math.abs(x), yourCustomFunc(7), or in your second case this can be 1 or (1). Expression 1 after evaluation is the same as (1) and the same as (((((1)))))) or even as something really bizarre like (+(!(+(!1)))).

提交回复
热议问题