Explicit vs Implicit Returns in Javascript
Often when reading through javascript examples you will find some arrow
functions use parentheses () while others use braces {}. This key
difference is that parentheses will implicitly return the last statement while
braces require an explicit return statement. It is important to understand the
difference between them because it is likely that you will find code examples
of both and trying to edit code written differently than you’re used to may
have unintended consequences.
[1] # [2]
Arrow functions are one-liner functions in javascript that have two main syntactical ways to create the code block. with parentheses and braces. Let’s take a look at both ways of creating arrow functions so that when we come accross them in the wild it will all make sense.
[3] # [4]
Here is an example of an arrow function that will implicitly return the last
statement without the return keyword. I believe that these are a bit more restricted
in that you cannot set variables inside them. They are ...