Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

javascript - ESCMAScript 6 arrow functions - parentheses around parameter

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...