When should I use `return` in es6 Arrow Functions?

后端 未结 5 2214
后悔当初
后悔当初 2020-11-21 05:40

The new es6 arrow functions say return is implicit under some circumstances:

The expression is also the implicit return value of that fun

5条回答
  •  北海茫月
    2020-11-21 06:05

    I understand this rule-of-thumb ...

    For functions that are effectively transforms (one-line-manipulations of arguments), return is implicit.

    Candidates are:

    // square-root 
    value => Math.sqrt(value)
    
    // sum
    (a,b) => a+b
    

    For other operations (more than one-liners that require a block, return has to be explicit

提交回复
热议问题