Skip to content

Commit 4daafa4

Browse files
Mohamed3onmbeaudru
authored andcommitted
Improve the explicit/implicit return section (mbeaudru#77)
* Improve the explicit/implicit return section * Improve the wording * Separate implicit and explicit examples * Add an example for when implicit return doesn't work. * Improved explanation and removed some things Improved the explanatory sentence for implicit return and removed a portion of code that didn't had its place in this part of the detailed explanation.
1 parent 59c6062 commit 4daafa4

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,16 @@ An **explicit return** is a function where the *return* keyword is used in its b
360360

361361
In the traditional way of writing functions, the return was always explicit. But with arrow functions, you can do *implicit return* which means that you don't need to use the keyword *return* to return a value.
362362

363-
To do an implicit return, the code must be written in a one-line sentence.
364-
365363
```js
366364
const double = (x) => {
367365
return x * 2; // Explicit return here
368366
}
369367
```
370368

371-
Since there only is a return value here, we can do an implicit return.
369+
Since this function only returns something (no instructions before the *return* keyword) we can do an implicit return.
372370

373371
```js
374-
const double = (x) => x * 2;
372+
const double = (x) => x * 2; // Correct, returns x*2
375373
```
376374

377375
To do so, we only need to **remove the brackets** and the **return** keyword. That's why it's called an *implicit* return, the *return* keyword is not there, but this function will indeed return ```x * 2```.

0 commit comments

Comments
 (0)