DEV Community

Discussion on: what's the difference between () => {} and () => ()

Collapse
 
pentacular profile image
pentacular • Edited

() => {} is this:
() => { return something }

and

() => () is the same but without the explicit return statement:
() => (something)

These are not the same.

This is a block of statements.

{ return something; }
Enter fullscreen mode Exit fullscreen mode

This is an expression

(something)
Enter fullscreen mode Exit fullscreen mode

They are very different things.

An expression evaluates to a value.

A block executes statements and does not evaluate to a value.
One of the statements in the block may be a return statement which causes the call to the function to evaluate to the returned value.

Differentiating clearly between statements and expressions will make your life easier.

While that is wrong, you can do this.
() => (return(

))

Unless you rewrite that return out or rewrite it to be in a block of statements, you cannot do this.

Collapse
 
muhdmirzamz profile image
MZ

Thank you for this. I may need to have another glance at your examples for me to fully comprehend it!