You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/17-arrow-functions-basics/article.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ As you can see, `(a, b) => a + b` means a function that accepts two arguments na
48
48
alert( double(3) ); // 6
49
49
```
50
50
51
-
- If there are no arguments, parentheses will be empty (but they should be present):
51
+
- If there are no arguments, parentheses are empty, but they must be present:
52
52
53
53
```js run
54
54
let sayHi = () => alert("Hello!");
@@ -76,9 +76,9 @@ They are very convenient for simple one-line actions, when we're just too lazy t
76
76
77
77
## Multiline arrow functions
78
78
79
-
The examples above took arguments from the left of `=>`and evaluated the right-side expression with them.
79
+
The arrow functions that we've seen so far were very simple. Theytook arguments from the left of`=>`, evaluated and returned the right-side expression with them.
80
80
81
-
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.
81
+
Sometimes we need a more complexfunction, 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 (justlikearegularfunction does).
82
82
83
83
Like this:
84
84
@@ -105,7 +105,7 @@ For now, we can already use arrow functions for one-line actions and callbacks.
105
105
106
106
## Summary
107
107
108
-
Arrow functions are handy for one-liners. They come in two flavors:
108
+
Arrow functions are handy for simple actions, especially for one-liners. They come in two flavors:
109
109
110
-
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
110
+
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`.
111
111
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.
0 commit comments