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

Categories

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

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

1 Answer

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...