Skip to content

Commit 1394eae

Browse files
authored
Merge branch 'master' into patch-2
2 parents 7eb35e0 + 911bf18 commit 1394eae

File tree

17 files changed

+89
-76
lines changed

17 files changed

+89
-76
lines changed

1-js/02-first-steps/07-operators/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Operators
22

3-
Many operators are known to us from school. It is an addition `+`, a multiplication `*`, a substraction `-` and so on.
3+
Many operators are known to us from school. It is an addition `+`, a multiplication `*`, a subtraction `-` and so on.
44

55
In this chapter we concentrate on aspects that are not covered by the school arithmetic.
66

@@ -11,24 +11,24 @@ In this chapter we concentrate on aspects that are not covered by the school ari
1111
Before we move on, let's grasp the common terminology.
1212

1313
- *An operand* -- is what operators are applied to. For instance in multiplication `5 * 2` there are two operands: the left operand is `5`, and the right operand is `2`. Sometimes people say "arguments" instead of "operands".
14-
- An operator is *unary* if it has a single operand. For example, the unary minus `"-"` reverses the sign of the number:
14+
- An operator is *unary* if it has a single operand. For example, the unary negation `"-"` reverses the sign of the number:
1515

1616
```js run
1717
let x = 1;
1818

1919
*!*
2020
x = -x;
2121
*/!*
22-
alert( x ); // -1, unary minus was applied
22+
alert( x ); // -1, unary negation was applied
2323
```
2424
- An operator is *binary* if it has two operands. The same minus exists in the binary form as well:
2525

2626
```js run no-beautify
2727
let x = 1, y = 3;
28-
alert( y - x ); // 2, binary minus substracts values
28+
alert( y - x ); // 2, binary minus subtracts values
2929
```
3030

31-
Formally, we're talking about the two different operators here: the unary minus (single operand, reverses the sign) and the binary minus (two operands, substracts).
31+
Formally, we're talking about the two different operators here: the unary negation (single operand, reverses the sign) and the binary subtraction (two operands, subtracts).
3232
3333
## Strings concatenation, binary +
3434
@@ -135,11 +135,11 @@ An extract from the [precedence table](https://developer.mozilla.org/en/JavaScri
135135
| Precedence | Name | Sign |
136136
|------------|------|------|
137137
| ... | ... | ... |
138-
| 15 | unary plus | `+` |
139-
| 15 | unary minus | `-` |
138+
| 16 | unary plus | `+` |
139+
| 16 | unary negation | `-` |
140140
| 14 | multiplication | `*` |
141141
| 14 | division | `/` |
142-
| 13 | addition (binary) | `+` |
142+
| 13 | addition | `+` |
143143
| 13 | subtraction | `-` |
144144
| ... | ... | ... |
145145
| 3 | assignment | `=` |
@@ -194,7 +194,7 @@ alert( a ); // 3
194194
alert( c ); // 0
195195
```
196196
197-
In the example above, the result of `(a = b + 1)` is the value which is assigned to `a` (that is `3`). It is then used to substract from `3`.
197+
In the example above, the result of `(a = b + 1)` is the value which is assigned to `a` (that is `3`). It is then used to subtract from `3`.
198198
199199
Funny code, isn't it? We should understand how it works, because sometimes we can see it in 3rd-party libraries, but shouldn't write anything like that ourselves. Such tricks definitely don't make the code clearer and readable.
200200
````

1-js/02-first-steps/08-comparison/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ alert( 0 === false ); // false, because the types are different
136136

137137
There also exists a "strict non-equality" operator `!==`, as an analogy for `!=`.
138138

139-
The string equality check operator is a bit longer to write, but makes it obvious what's going on and leaves less space for errors.
139+
The strict equality check operator is a bit longer to write, but makes it obvious what's going on and leaves less space for errors.
140140

141141
## Comparison with null and undefined
142142

1-js/02-first-steps/09-alert-prompt-confirm/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For example:
2222
alert("Hello");
2323
```
2424

25-
The mini-window with the message is called a *modal window*. The word "modal" means that the visitor can't interact with the rest of the page, press other buttons etc, until they deal with the window. In this case -- until they press "OK".
25+
The mini-window with the message is called a *modal window*. The word "modal" means that the visitor can't interact with the rest of the page, press other buttons etc, until they have dealt with the window. In this case -- until they press "OK".
2626

2727
## prompt
2828

@@ -101,7 +101,7 @@ We covered 3 browser-specific functions to interact with the visitor:
101101
`confirm`
102102
: shows a message and waits the user to press "OK" or "CANCEL". It returns `true` for OK and `false` for CANCEL/`key:Esc`.
103103
104-
All these methods are modal: they pause the script execution and don't let the visitor to interact with the rest of the page until he dismisses them.
104+
All these methods are modal: they pause the script execution and don't allow the visitor to interact with the rest of the page until the message has been dismissed.
105105
106106
There are two limitations shared by all the methods above:
107107

1-js/02-first-steps/10-ifelse/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ if (age > 18) {
126126
alert(accessAllowed);
127127
```
128128

129-
The so-called "ternary" or "question mark" operator allows to do that shorter and simpler.
129+
The so-called "ternary" or "question mark" operator lets us do that shorter and simpler.
130130

131131
The operator is represented by a question mark `"?"`. The formal term "ternary" means that the operator has 3 operands. It is actually the one and only operator in JavaScript which has that many.
132132

@@ -143,7 +143,7 @@ For example:
143143
let accessAllowed = (age > 18) ? true : false;
144144
```
145145

146-
Technically, we can omit parentheses around `age > 14`. The question mark operator has a low precedence. It executes after the comparison `>`, so that'll do the same:
146+
Technically, we can omit parentheses around `age > 18`. The question mark operator has a low precedence. It executes after the comparison `>`, so that'll do the same:
147147

148148
```js
149149
// the comparison operator "age > 18" executes first anyway

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The "OR" operator is represented with two vertical line symbols:
1616
result = a || b;
1717
```
1818

19-
In classical programming, logical OR is meant to manipulate boolean values. If any of it's arguments is `true`, then it returns `true`, otherwise -- returns `false`.
19+
In classical programming, logical OR is meant to manipulate boolean values only. If any of its arguments are `true`, then it returns `true`, otherwise it returns `false`.
2020

2121
In JavaScript the operator is a little bit more tricky and powerful. But first let's see what happens with boolean values.
2222

@@ -62,7 +62,7 @@ let hour = 12;
6262
let isWeekend = true;
6363

6464
if (hour < 10 || hour > 18 || isWeekend) {
65-
alert( 'The office is closed.' ); // it is weekend
65+
alert( 'The office is closed.' ); // it is the weekend
6666
}
6767
```
6868

@@ -78,13 +78,13 @@ Given multiple OR'ed values:
7878
result = value1 || value2 || value3;
7979
```
8080

81-
The OR `"||"` operator is doing the following:
81+
The OR `"||"` operator does the following:
8282

83-
- Evalutes operands from left to right.
84-
- For each value -- converts it to boolean. If it's true then stops and returns that value.
85-
- If operands finished, returns the last value.
83+
- Evalute operands from left to right.
84+
- For each operand, convert it to boolean. If the result is `true`, then stop and return that the original value of that operand.
85+
- If all other operands have been assessed (i.e. all were `falsy`), return the last operand.
8686

87-
A value is returned in it's original form, without the conversion.
87+
A value is returned in its original form, without the conversion.
8888

8989
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value found.
9090

@@ -159,7 +159,7 @@ The AND operator is represented with two ampersands `&&`:
159159
result = a && b;
160160
```
161161

162-
In classical programming AND returns `true` if both operands are truthy and `false` -- otherwise:
162+
In classical programming AND returns `true` if both operands are truthy and `false` otherwise:
163163

164164
```js run
165165
alert( true && true ); // true
@@ -196,26 +196,26 @@ Given multiple AND'ed values:
196196
result = value1 && value2 && value3;
197197
```
198198
199-
The AND `"&&"` operator is doing the following:
199+
The AND `"&&"` operator does the following:
200200
201-
- Evalutes operands from left to right.
202-
- For each value converts it to a boolean. If the result is `false`, stops and returns the original value.
203-
- If values finished (all are truthy), returns the last one.
201+
- Evalute operands from left to right.
202+
- For each operand, convert it to a boolean. If the result is `false`, stop and return the original value of that operand.
203+
- If all other operands have been assessed (i.e. all were truthy), return the last operand.
204204
205-
In other words, AND returns the first falsy value or the last value if none found.
205+
In other words, AND returns the first falsy value or the last value if none were found.
206206
207207
The rules above are similar to OR. The difference is that AND returns the first *falsy* value while OR returns the first *truthy* one.
208208
209209
Examples:
210210
211211
```js run
212212
// if the first operand is truthy,
213-
// AND returns the second one:
213+
// AND returns the second operand:
214214
alert( 1 && 0 ); // 0
215215
alert( 1 && 5 ); // 5
216216
217217
// if the first operand is falsy,
218-
// AND returns it, and the second one is ignored
218+
// AND returns it. The second operand is ignored
219219
alert( null && 5 ); // null
220220
alert( 0 && "no matter what" ); // 0
221221
```
@@ -266,7 +266,7 @@ if (x > 0) {
266266
267267
The variant with `&&` appears to be shorter. But `if` is more obvious and tends to be a little bit more readable.
268268
269-
So it is recommended to use every construct for it's purpose. Use `if` if we want if. And use `&&` if we want AND.
269+
So it is recommended to use every construct for its purpose. Use `if` if we want if. And use `&&` if we want AND.
270270
271271
## ! (NOT)
272272
@@ -297,9 +297,9 @@ alert( !!"non-empty string" ); // true
297297
alert( !!null ); // false
298298
```
299299
300-
That is: the first NOT converts the value to boolean and returns the inverse, and the second NOT inverses it again, at the end we have a plain value-to-boolean conversion.
300+
That is, the first NOT converts the value to boolean and returns the inverse, and the second NOT inverses it again. At the end we have a plain value-to-boolean conversion.
301301
302-
There's a little more verbose to do the same -- a built-in `Boolean` function:
302+
There's a little more verbose way to do the same thing -- a built-in `Boolean` function:
303303

304304
```js run
305305
alert( Boolean("non-empty string") ); // true

1-js/02-first-steps/12-while-for/5-replace-for-while/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 5
44

55
# Replace "for" with "while"
66

7-
Rewrite the code changing the `for` loop to `while` without altering it's behavior (the output should stay same).
7+
Rewrite the code changing the `for` loop to `while` without altering its behavior (the output should stay same).
88

99
```js run
1010
for (let i = 0; i < 3; i++) {

1-js/02-first-steps/12-while-for/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ if (i < 3) { alert(i); i++ }
142142
```
143143

144144
````smart header="Inline variable declaration"
145-
Here the "counter" variable `i` is declared right in the loop. That's called an "inline" variable declaration. Such variable is visible only inside the loop.
145+
Here the "counter" variable `i` is declared right in the loop. That's called an "inline" variable declaration. Such variables are visible only inside the loop.
146146
147147
```js run
148148
for (*!*let*/!* i = 0; i < 3; i++) {
@@ -202,15 +202,15 @@ for (;;) {
202202
}
203203
```
204204

205-
Please note that the two `for` semicolons `;` must present, otherwise it would be a syntax error.
205+
Please note that the two `for` semicolons `;` must be present, otherwise it would be a syntax error.
206206

207207
## Breaking the loop
208208

209209
Normally the loop exits when the condition becomes falsy.
210210

211211
But we can force the exit at any moment. There's a special `break` directive for that.
212212

213-
For example, this code below asks user for numbers and breaks if no number entered:
213+
For example, the loop below asks the user for a series of numbers, but "breaks" when no number is entered:
214214

215215
```js
216216
let sum = 0;
@@ -353,7 +353,7 @@ In the code above `break outer` looks upwards for the label named `outer` and br
353353

354354
So the control goes straight from `(*)` to `alert('Done!')`.
355355

356-
We can also move a label into the separate string:
356+
We can also move the label onto a separate line:
357357

358358
```js no-beautify
359359
outer:

1-js/03-code-quality/02-coding-style/article.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ Nothing is "carved in stone" here. Everything is optional and can be changed: th
4646

4747
In most JavaScript projects figure brackets are written on the same line, not on the new line. A so-called "egyptian" style. There's also a space before an opening bracket.
4848

49-
An edge case is a single-line `if/for`. Should we use brackets at all? If yes, then where?
49+
Like this:
50+
51+
```js
52+
if (condition) {
53+
// do this
54+
// ...and that
55+
// ...and that
56+
}
57+
```
58+
59+
A single-line construct is an important edge case. Should we use brackets at all? If yes, then where?
5060

5161
Here are the annotated variants, so you can judge about their readability on your own:
5262

@@ -82,9 +92,9 @@ There are two types of indents:
8292

8393
- **A horizontal indent: 2(4) spaces.**
8494

85-
A horizantal identation is made using either 2 or 4 spaces or the "Tab" symbol. Which one to choose is a kind of an old holy war. Spaces are more common nowadays.
95+
A horizantal identation is made using either 2 or 4 spaces or the "Tab" symbol. Which one to choose is an old holy war. Spaces are more common nowadays.
8696

87-
One of advantages of spaces over tabs is that they allow more flexible configurations of indents than the "Tab" symbol.
97+
One of advantages of spaces over tabs is that spaces allow more flexible configurations of indents than the "Tab" symbol.
8898

8999
For instance, we can align the arguments with the opening bracket, like this:
90100

@@ -99,7 +109,7 @@ There are two types of indents:
99109
}
100110
```
101111

102-
- **A vertical indent: empty lines for splitting the code in logical blocks.**
112+
- **A vertical indent: empty lines for splitting code into logical blocks.**
103113

104114
Even a single function can often be divided in logical blocks. In the example below, the initialization of variables, the main loop and returning the result are split vertically:
105115

@@ -121,9 +131,9 @@ There are two types of indents:
121131

122132
A semicolon should be present after each statement. Even if it could be possibly be skipped.
123133

124-
There are languages where a semicolon is truly optional. It's rarely used there.
134+
There are languages where a semicolon is truly optional. It's rarely used there. But in JavaScript there are few cases when a line break is sometimes not interpreted as a semicolon. That leaves a place for programming errors.
125135
126-
But in JavaScript there are few cases when a line break is sometimes not interpreted as a semicolon. That leaves a place for programming errors, so semicolons should be at place.
136+
As you become more mature as a programmer, you may choose a no-semicolon style, like [StandardJS](https://standardjs.com/), but that's only when you know JavaScript well and understand possible pitfalls.
127137

128138
### Nesting levels
129139

@@ -240,7 +250,7 @@ If you are writing several "helper" functions and the code to use them, then the
240250
...
241251
}
242252
```
243-
3. Mixed, a function is described where it's first used.
253+
3. Mixed: a function is described where it's first used.
244254

245255
Most of time, the second variant is preferred.
246256

@@ -259,6 +269,7 @@ For instance:
259269
- [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml)
260270
- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
261271
- [Idiomatic.JS](https://github.com/rwaldron/idiomatic.js)
272+
- [StandardJS](https://standardjs.com/)
262273
- (there are more)
263274

264275
If you're a novice developer, then you could start with the cheatsheet above in the chapter, and later browse the style guides to pick up the common principles and maybe choose one.
@@ -267,7 +278,7 @@ If you're a novice developer, then you could start with the cheatsheet above in
267278
268279
There are tools that can check the code style automatically. They are called "linters".
269280
270-
The great thing about them is that style-checking also finds some bugs, like a typo in variable name or a function.
281+
The great thing about them is that style-checking also finds some bugs, like a typo in a variable or function name.
271282
272283
So it's recommended to install one, even if you don't want to stick to a "code style". They help to find typos -- and that's already good enough.
273284

@@ -314,7 +325,7 @@ Using a linter has the great side-effect. Linters catch typos. For instance, whe
314325

315326
For that reason even if you're not concerned about styles, using a linter is highly recommended.
316327
317-
Also certain IDEs support built-in linting, but not so tunable as ESLint.
328+
Also certain IDEs support built-in linting, that also may be good, but not so tunable as ESLint.
318329
319330
## Summary
320331

0 commit comments

Comments
 (0)