Skip to content

Commit 84db86f

Browse files
authored
Merge pull request #370 from brentguf/functions
Functions chapter
2 parents c99499e + 1868774 commit 84db86f

File tree

2 files changed

+8
-8
lines changed
  • 1-js/02-first-steps/14-function-basics

2 files changed

+8
-8
lines changed

1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ Rewrite it, to perform the same, but without `if`, in a single line.
2222

2323
Make two variants of `checkAge`:
2424

25-
1. Using a question mark operator `'?'`
25+
1. Using a question mark operator `?`
2626
2. Using OR `||`

1-js/02-first-steps/14-function-basics/article.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function showMessage() {
2020
}
2121
```
2222

23-
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* in the brackets (empty in the example above) and finally the code of the function, also named "the function body".
23+
The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (empty in the example above) and finally the code of the function, also named "the function body", between curly braces.
2424

2525
![](function_basics.png)
2626

@@ -41,7 +41,7 @@ showMessage();
4141

4242
The call `showMessage()` executes the code of the function. Here we will see the message two times.
4343

44-
This example clearly demonstrates one of the main purposes of functions: to evade code duplication.
44+
This example clearly demonstrates one of the main purposes of functions: to avoid code duplication.
4545

4646
If we ever need to change the message or the way it is shown, it's enough to modify the code in one place: the function which outputs it.
4747

@@ -117,7 +117,7 @@ function showMessage() {
117117
alert(message);
118118
}
119119

120-
// the function will create and use it's own userName
120+
// the function will create and use its own userName
121121
showMessage();
122122

123123
alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable
@@ -128,7 +128,7 @@ Variables declared outside of any function, such as the outer `userName` in the
128128
129129
Global variables are visible from any function (unless shadowed by locals).
130130
131-
Usually, a function declares all variables specific to its task, and global variables only store project-level data, so important that it really must be seen from anywhere. Modern code has few or no globals. Most variables reside in their functions.
131+
Usually, a function declares all variables specific to its task. Global variables only store project-level data, so when it's important that these variables are accesible from anywhere. Modern code has few or no globals. Most variables reside in their functions.
132132
```
133133

134134
## Parameters
@@ -376,7 +376,7 @@ These examples assume common meanings of prefixes. What they mean for you is det
376376
```smart header="Ultrashort function names"
377377
Functions that are used *very often* sometimes have ultrashort names.
378378

379-
For example, [jQuery](http://jquery.com) framework defines a function `$`, [LoDash](http://lodash.com/) library has it's core function named `_`.
379+
For example, the [jQuery](http://jquery.com) framework defines a function `$`. The [LoDash](http://lodash.com/) library has its core function named `_`.
380380

381381
These are exceptions. Generally functions names should be concise, but descriptive.
382382
```
@@ -424,7 +424,7 @@ function isPrime(n) {
424424
}
425425
```
426426
427-
The second variant is easier to understand isn't it? Instead of the code piece we see a name of the action (`isPrime`). Sometimes people refer to such code as *self-describing*.
427+
The second variant is easier to understand, isn't it? Instead of the code piece we see a name of the action (`isPrime`). Sometimes people refer to such code as *self-describing*.
428428
429429
So, functions can be created even if we don't intend to reuse them. They structure the code and make it readable.
430430
@@ -440,7 +440,7 @@ function name(parameters, delimited, by, comma) {
440440
441441
- Values passed to a function as parameters are copied to its local variables.
442442
- A function may access outer variables. But it works only from inside out. The code outside of the function doesn't see its local variables.
443-
- A function can return a value. If it doesn't then its result is `undefined`.
443+
- A function can return a value. If it doesn't, then its result is `undefined`.
444444
445445
To make the code clean and easy to understand, it's recommended to use mainly local variables and parameters in the function, not outer variables.
446446

0 commit comments

Comments
 (0)