Skip to content

Commit 044b234

Browse files
authored
Merge pull request #27 from 109149/master
minor fixes
2 parents 8bd4fe0 + 9d5c086 commit 044b234

File tree

38 files changed

+153
-132
lines changed

38 files changed

+153
-132
lines changed

1-js/01-getting-started/4-devtools/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To see errors and get a lot of other useful information about scripts, "develope
88

99
Most developers lean towards Chrome or Firefox for development because those browsers have the best developer tools. Other browsers also provide developer tools, sometimes with special features, but are usually playing "catch-up" to Chrome or Firefox. So most developers have a "favorite" browser and switch to others if a problem is browser-specific.
1010

11-
Developer tools are potent, they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
11+
Developer tools are potent; they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
1212

1313
## Google Chrome
1414

1-js/02-first-steps/02-structure/article.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,36 @@ Errors which occur in such cases are quite hard to find and fix.
5656
If you're curious to see a concrete example of such an error, check this code out:
5757
5858
```js run
59-
[1, 2].forEach(alert)
59+
alert("Hello");
60+
61+
[1, 2].forEach(alert);
6062
```
6163
62-
No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of the code: it shows `1` then `2`.
64+
No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of running the code: it shows `Hello`, then `1`, then `2`.
6365
64-
Now, let's add an `alert` before the code and *not* finish it with a semicolon:
66+
Now let's remove the semicolon after the `alert`:
6567
6668
```js run no-beautify
67-
alert("There will be an error")
69+
alert("Hello")
6870
69-
[1, 2].forEach(alert)
71+
[1, 2].forEach(alert);
7072
```
7173
72-
Now if we run the code, only the first `alert` is shown and then we have an error!
73-
74-
But everything is fine again if we add a semicolon after `alert`:
75-
```js run
76-
alert("All fine now");
74+
The difference compared to the code above is only one character: the semicolon at the end of the first line is gone.
7775
78-
[1, 2].forEach(alert)
79-
```
76+
If we run this code, only the first `Hello` shows (and there's an error, you may need to open the console to see it). There are no numbers any more.
8077
81-
Now we have the "All fine now" message followed by `1` and `2`.
78+
That's because JavaScript does not assume a semicolon before square brackets `[...]`. So, the code in the last example is treated as a single statement.
8279
83-
84-
The error in the no-semicolon variant occurs because JavaScript does not assume a semicolon before square brackets `[...]`.
85-
86-
So, because the semicolon is not auto-inserted, the code in the first example is treated as a single statement. Here's how the engine sees it:
80+
Here's how the engine sees it:
8781
8882
```js run no-beautify
89-
alert("There will be an error")[1, 2].forEach(alert)
83+
alert("Hello")[1, 2].forEach(alert);
9084
```
9185
92-
But it should be two separate statements, not one. Such a merging in this case is just wrong, hence the error. This can happen in other situations.
86+
Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly.
87+
88+
This can happen in other situations also.
9389
````
9490

9591
We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ alert('1' + 2 + 2); // "122" and not "14"
115115
```
116116
Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`.
117117
118+
```js run
119+
alert('1' + 2 + 2); // "122" and not "14"
120+
```
121+
Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`.
122+
118123
The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers.
119124

120125
Here's the demo for subtraction and division:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Logical operators
1+
# Logical operators: ||, && and !
22

33
There are four logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT), `??` (Nullish Coalescing). Here we cover the first three, the `??` operator is in the next article.
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ Functions that are used *very often* sometimes have ultrashort names.
411411

412412
For example, the [jQuery](http://jquery.com) framework defines a function with `$`. The [Lodash](http://lodash.com/) library has its core function named `_`.
413413

414-
These are exceptions. Generally functions names should be concise and descriptive.
414+
These are exceptions. Generally function names should be concise and descriptive.
415415
```
416416

417417
## Functions == Comments

1-js/03-code-quality/05-testing-mocha/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Automated testing will be used in further tasks, and it's also widely used in real projects.
44

5-
## Why we need tests?
5+
## Why do we need tests?
66

77
When we write a function, we can usually imagine what it should do: which parameters give which results.
88

1-js/03-code-quality/06-polyfills/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Modern project build systems, such as [webpack](http://webpack.github.io/), prov
4848
4949
New language features may include not only syntax constructs and operators, but also built-in functions.
5050
51-
For example, `Math.trunc(n)` is a function that "cuts off" the decimal part of a number, e.g `Math.trunc(1.23) = 1`.
51+
For example, `Math.trunc(n)` is a function that "cuts off" the decimal part of a number, e.g `Math.trunc(1.23)` returns `1`.
5252
5353
In some (very outdated) JavaScript engines, there's no `Math.trunc`, so such code will fail.
5454

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ user = {
8181
// method shorthand looks better, right?
8282
user = {
8383
*!*
84-
sayHi() { // same as "sayHi: function()"
84+
sayHi() { // same as "sayHi: function(){...}"
8585
*/!*
8686
alert("Hello");
8787
}

1-js/05-data-types/01-primitives-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Objects are "heavier" than primitives. They require additional resources to supp
3939

4040
Here's the paradox faced by the creator of JavaScript:
4141

42-
- There are many things one would want to do with a primitive like a string or a number. It would be great to access them as methods.
42+
- There are many things one would want to do with a primitive like a string or a number. It would be great to access them using methods.
4343
- Primitives must be as fast and lightweight as possible.
4444

4545
The solution looks a little bit awkward, but here it is:

1-js/05-data-types/04-array/article.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,7 @@ alert( arr[0] ); // undefined! no elements.
379379
alert( arr.length ); // length 2
380380
```
381381

382-
In the code above, `new Array(number)` has all elements `undefined`.
383-
384-
To evade such surprises, we usually use square brackets, unless we really know what we're doing.
382+
To avoid such surprises, we usually use square brackets, unless we really know what we're doing.
385383

386384
## Multidimensional arrays
387385

0 commit comments

Comments
 (0)