Arrow functions and the use of parentheses () or {} or ({})

后端 未结 2 1258
天涯浪人
天涯浪人 2020-11-30 00:35

I cannot understand why in the arrow functions we do not need to wrap the literal of arrow function in the ({}) braces, instead of in this exam

2条回答
  •  被撕碎了的回忆
    2020-11-30 01:09

    const add = ( a, b ) => ( a + b )

    Is equivalent to

    const add = ( a, b ) => { return a+b; }

    When you use the () after your => it just automatically returns the values inside.

    Edit: you can also ommit the () entirely, thanks to Tom Fenesh

提交回复
热议问题