ESCMAScript 6 arrow functions - parentheses around parameter

前端 未结 1 531
半阙折子戏
半阙折子戏 2020-12-11 09:20

I\'m new to javascript and cannot understand simple thing - what is the difference between

...(x) => { return x*2}

and

.         


        
相关标签:
1条回答
  • 2020-12-11 09:35

    The parenthesis around input arguments (x in this case) are only required when there are two or more input arguments. With just one (as you've shown here), the two statements are identical.

    (x) => { return x * 2; } is the same as x => { return x * 2; }

    But,

    (x, y) => { return x * y; }

    Requires parenthesis around the input arguments.

    See this for all the gory details!

    0 讨论(0)
提交回复
热议问题