ESCMAScript 6 arrow functions - parentheses around parameter

僤鯓⒐⒋嵵緔 提交于 2020-01-30 08:33:05

问题


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

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

and

...x => { return x*2} //(just for example, may not work)

Can someone explain or give link for description?


回答1:


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!



来源:https://stackoverflow.com/questions/43877630/escmascript-6-arrow-functions-parentheses-around-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!