Arrow function without curly braces

前端 未结 7 1086
生来不讨喜
生来不讨喜 2020-11-22 10:52

I\'m new to both ES6 and React and I keep seeing arrow functions. Why is it that some arrow functions use curly braces after the fat arrow and some use parentheses? For exam

7条回答
  •  死守一世寂寞
    2020-11-22 11:13

    Actually in a briefcase when somebody uses braces in an arrow function declaration, it is equal to below:

    const arrow = number => number + 1;
    
    |||
    
    const arrow = (number) => number + 1;
    
    |||    
    
    const arrow = (number) => ( number + 1 );
    
    |||
    
    const arrow = (number) => { return number + 1 };
    

提交回复
热议问题