Skip to content

Commit 1615777

Browse files
Merge pull request #167
main sync
2 parents 0957ea0 + 44b556f commit 1615777

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

1-js/02-first-steps/16-function-expressions/article.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Everything would work the same.
9090

9191

9292
````smart header="Why is there a semicolon at the end?"
93-
You might wonder, why does Function Expression have a semicolon `;` at the end, but Function Declaration does not:
93+
You might wonder, why do Function Expressions have a semicolon `;` at the end, but Function Declarations do not:
9494
9595
```js
9696
function sayHi() {
@@ -144,13 +144,13 @@ function showCancel() {
144144
ask("Do you agree?", showOk, showCancel);
145145
```
146146

147-
In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such function usually draws a nice-looking question window. But that's another story.
147+
In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such functions usually draw a nice-looking question window. But that's another story.
148148

149149
**The arguments `showOk` and `showCancel` of `ask` are called *callback functions* or just *callbacks*.**
150150

151151
The idea is that we pass a function and expect it to be "called back" later if necessary. In our case, `showOk` becomes the callback for "yes" answer, and `showCancel` for "no" answer.
152152

153-
We can use Function Expressions to write the same function much shorter:
153+
We can use Function Expressions to write an equivalent, shorter function:
154154

155155
```js run no-beautify
156156
function ask(question, yes, no) {
@@ -186,15 +186,15 @@ Let's formulate the key differences between Function Declarations and Expression
186186

187187
First, the syntax: how to differentiate between them in the code.
188188

189-
- *Function Declaration:* a function, declared as a separate statement, in the main code flow.
189+
- *Function Declaration:* a function, declared as a separate statement, in the main code flow:
190190

191191
```js
192192
// Function Declaration
193193
function sum(a, b) {
194194
return a + b;
195195
}
196196
```
197-
- *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" `=`:
197+
- *Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created on the right side of the "assignment expression" `=`:
198198

199199
```js
200200
// Function Expression
@@ -291,7 +291,7 @@ if (age < 18) {
291291
welcome(); // \ (runs)
292292
*/!*
293293
// |
294-
function welcome() { // |
294+
function welcome() { // |
295295
alert("Hello!"); // | Function Declaration is available
296296
} // | everywhere in the block where it's declared
297297
// |
@@ -301,7 +301,7 @@ if (age < 18) {
301301

302302
} else {
303303

304-
function welcome() {
304+
function welcome() {
305305
alert("Greetings!");
306306
}
307307
}
@@ -360,7 +360,7 @@ welcome(); // ok now
360360

361361

362362
```smart header="When to choose Function Declaration versus Function Expression?"
363-
As a rule of thumb, when we need to declare a function, the first to consider is Function Declaration syntax. It gives more freedom in how to organize our code, because we can call such functions before they are declared.
363+
As a rule of thumb, when we need to declare a function, the first thing to consider is Function Declaration syntax. It gives more freedom in how to organize our code, because we can call such functions before they are declared.
364364
365365
That's also better for readability, as it's easier to look up `function f(…) {…}` in the code than `let f = function(…) {…};`. Function Declarations are more "eye-catching".
366366

1-js/02-first-steps/17-arrow-functions-basics/article.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ As you can see, `(a, b) => a + b` means a function that accepts two arguments na
4848
alert( double(3) ); // 6
4949
```
5050

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:
5252

5353
```js run
5454
let sayHi = () => alert("Hello!");
@@ -64,7 +64,7 @@ For instance, to dynamically create a function:
6464
let age = prompt("What is your age?", 18);
6565
6666
let welcome = (age < 18) ?
67-
() => alert('Hello') :
67+
() => alert('Hello!') :
6868
() => alert("Greetings!");
6969
7070
welcome();
@@ -76,9 +76,9 @@ They are very convenient for simple one-line actions, when we're just too lazy t
7676
7777
## Multiline arrow functions
7878
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. They took arguments from the left of `=>`, evaluated and returned the right-side expression with them.
8080

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 complex function, with multiple expressions and statements. In that case, 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).
8282

8383
Like this:
8484

@@ -105,7 +105,7 @@ For now, we can already use arrow functions for one-line actions and callbacks.
105105
106106
## Summary
107107
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:
109109
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`.
111111
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.

1-js/02-first-steps/18-javascript-specials/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ To fully enable all features of modern JavaScript, we should start scripts with
5555

5656
The directive must be at the top of a script or at the beginning of a function body.
5757

58-
Without `"use strict"`, everything still works, but some features behave in the old-fashion, "compatible" way. We'd generally prefer the modern behavior.
58+
Without `"use strict"`, everything still works, but some features behave in the old-fashioned, "compatible" way. We'd generally prefer the modern behavior.
5959

6060
Some modern features of the language (like classes that we'll study in the future) enable strict mode implicitly.
6161

@@ -144,7 +144,7 @@ Assignments
144144
: There is a simple assignment: `a = b` and combined ones like `a *= 2`.
145145

146146
Bitwise
147-
: Bitwise operators work with 32-bit integers at the lowest, bit-level: see the [docs](mdn:/JavaScript/Guide/Expressions_and_Operators#Bitwise) when they are needed.
147+
: Bitwise operators work with 32-bit integers at the lowest, bit-level: see the [docs](mdn:/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) when they are needed.
148148

149149
Conditional
150150
: The only operator with three parameters: `cond ? resultA : resultB`. If `cond` is truthy, returns `resultA`, otherwise `resultB`.
@@ -256,7 +256,7 @@ We covered three ways to create a function in JavaScript:
256256
3. Arrow functions:
257257
258258
```js
259-
// expression at the right side
259+
// expression on the right side
260260
let sum = (a, b) => a + b;
261261
262262
// or multi-line syntax with { ... }, need return here:

0 commit comments

Comments
 (0)