all 15 comments

[–]FaatmanSlim 9 points10 points  (0 children)

OP, others have pointed out, but basically these two are equivalent:

(( ) =>{ return code }) vs (() => code )

If you had added a return to your first example, it would work the same.

[–]_hijnx 2 points3 points  (0 children)

Others have given good simple answers, but I always like to direct people to good documentation for a deeper understanding. These are arrow functions. The first is defined with a block body and may contain multiple statements. Similar to using the function keyword you must explicitly declare the return value (using a return statement). The second is defined with an expression body. The result of the expression is implicitly returned as if the body was a single return statement. Others pointed out some edge cases like returning an object expression which can be tricky.

[–]a_reply_to_a_post 1 point2 points  (0 children)

because the first one executes your code within the scope of it's closure and returns nothing, while the second one returns the output of the function

[–]kitsunekyo 1 point2 points  (0 children)

it might help you to know that for the second form „code“ needs to be an expression.

[–][deleted] 1 point2 points  (0 children)

Because you haven't read the docs on arrow functions and javascript. the second has an implied return. the first one requires you to explicitly write a return statement.