minor fixes
This commit is contained in:
parent
741d90ce8a
commit
4585dbb322
1 changed files with 5 additions and 5 deletions
|
@ -48,7 +48,7 @@ As you can see, `(a, b) => a + b` means a function that accepts two arguments na
|
||||||
alert( double(3) ); // 6
|
alert( double(3) ); // 6
|
||||||
```
|
```
|
||||||
|
|
||||||
- If there are no arguments, parentheses will be empty (but they should be present):
|
- If there are no arguments, parentheses are empty, but they must be present:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
let sayHi = () => alert("Hello!");
|
let sayHi = () => alert("Hello!");
|
||||||
|
@ -76,9 +76,9 @@ They are very convenient for simple one-line actions, when we're just too lazy t
|
||||||
|
|
||||||
## Multiline arrow functions
|
## Multiline arrow functions
|
||||||
|
|
||||||
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
|
The arrow functions that we've seen so far were very simple. They took arguments from the left of `=>`, evaluated and returned the right-side expression with them.
|
||||||
|
|
||||||
Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal `return` within them.
|
Sometimes we need a more complex function, with multiple expressions and statements. In that case, but we can enclose them in curly braces. The major difference is that curly braces require a `return` within them to return a value (just like a regular function does).
|
||||||
|
|
||||||
Like this:
|
Like this:
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ For now, we can already use arrow functions for one-line actions and callbacks.
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
Arrow functions are handy for one-liners. They come in two flavors:
|
Arrow functions are handy for simple actions, especially for one-liners. They come in two flavors:
|
||||||
|
|
||||||
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
|
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result. Parentheses can be omitted, if there's only a single argument, e.g. `n => n*2`.
|
||||||
2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.
|
2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue