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/15-function-expressions-arrows/article.md
+9-10Lines changed: 9 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -185,9 +185,8 @@ First, the syntax: how to see what is what in the code.
185
185
return a + b;
186
186
}
187
187
```
188
-
-*Function Expression:* a function, created inside an expression or inside another syntax construct.
189
-
190
-
Here, the function is created at the right side of the "assignment expression =":
188
+
-*Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created at the right side of the "assignment expression" `=`:
189
+
191
190
```js
192
191
// Function Expression
193
192
let sum = function(a, b) {
@@ -243,7 +242,7 @@ Function Expressions are created when the execution reaches them. That would hap
243
242
244
243
Sometimes that's handy to declare a local function only needed in that block alone. But that feature may also cause problems.
245
244
246
-
For instance, let's imagine that we need to declare a function `welcome()` depending on the `age` variable that we get in run time. And then we plan to use it some time later.
245
+
For instance, let's imagine that we need to declare a function `welcome()` depending on the `age` variable that we get during runtime. And then we plan to use it some time later.
247
246
248
247
The code below doesn't work:
249
248
@@ -298,7 +297,7 @@ if (age < 18) {
298
297
}
299
298
}
300
299
301
-
// Here we're out of figure brackets,
300
+
// Here we're out of curly braces,
302
301
// so we can not see Function Declarations made inside of them.
303
302
304
303
*!*
@@ -439,15 +438,15 @@ They are very convenient for simple one-line actions, when we're just too lazy t
439
438
440
439
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
441
440
442
-
Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in figure brackets. Then use a normal `return` within them.
441
+
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.
443
442
444
443
Like this:
445
444
446
445
```js run
447
-
let sum = (a, b) => { // the figure bracket opens a multiline function
446
+
let sum = (a, b) => { // the curly brace opens a multiline function
448
447
let result = a + b;
449
448
*!*
450
-
return result; // if we use figure brackets, use return to get results
449
+
return result; // if we use curly braces, use return to get results
451
450
*/!*
452
451
};
453
452
@@ -475,5 +474,5 @@ So we should use a Function Expression only when a Function Declaration is not f
475
474
476
475
Arrow functions are handy for one-liners. They come in two flavors:
477
476
478
-
1. Without figure brackets: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
479
-
2. With figure brackets: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.
477
+
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
478
+
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