refactor arrow functions
This commit is contained in:
parent
6165a9a727
commit
2aedc2df49
1 changed files with 6 additions and 2 deletions
|
@ -86,7 +86,7 @@ Like this:
|
||||||
let sum = (a, b) => { // the curly brace opens a multiline function
|
let sum = (a, b) => { // the curly brace opens a multiline function
|
||||||
let result = a + b;
|
let result = a + b;
|
||||||
*!*
|
*!*
|
||||||
return result; // if we use curly braces, use return to get results
|
return result; // if we use curly braces, then we need an explicit "return"
|
||||||
*/!*
|
*/!*
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,7 +94,11 @@ alert( sum(1, 2) ); // 3
|
||||||
```
|
```
|
||||||
|
|
||||||
```smart header="More to come"
|
```smart header="More to come"
|
||||||
Here we praised arrow functions for brevity. But that's not all! Arrow functions have other interesting features. We'll return to them later in the chapter <info:arrow-functions>.
|
Here we praised arrow functions for brevity. But that's not all!
|
||||||
|
|
||||||
|
Arrow functions have other interesting features.
|
||||||
|
|
||||||
|
To study them in-depth, we first need to get to know some other aspects of JavaScript, so we'll return to arrow functions later in the chapter <info:arrow-functions>.
|
||||||
|
|
||||||
For now, we can already use arrow functions for one-line actions and callbacks.
|
For now, we can already use arrow functions for one-line actions and callbacks.
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue