Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/10-basics/10-hello-world/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

```javascript
console.log("it's JavaScript"
console.log(it's JavaScript")
consol.log("it's JavaScript")
console.log('it's JavaScript")
consolelog("it's JavaScript")
console.log(it's JavaScript");

Check notice on line 40 in modules/10-basics/10-hello-world/en/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/10-basics/10-hello-world/en/README.md#L40

Unpaired symbol: ‘'’ seems to be missing (EN_UNPAIRED_QUOTES) URL: https://languagetool.org/insights/post/punctuation-guide/#what-are-parentheses Rule: https://community.languagetool.org/rule/show/EN_UNPAIRED_QUOTES?lang=en-US Category: PUNCTUATION
Raw output
modules/10-basics/10-hello-world/en/README.md:40:13: Unpaired symbol: ‘'’ seems to be missing (EN_UNPAIRED_QUOTES)
 URL: https://languagetool.org/insights/post/punctuation-guide/#what-are-parentheses 
 Rule: https://community.languagetool.org/rule/show/EN_UNPAIRED_QUOTES?lang=en-US
 Category: PUNCTUATION

Check notice on line 40 in modules/10-basics/10-hello-world/en/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/10-basics/10-hello-world/en/README.md#L40

Unpaired symbol: ‘"’ seems to be missing (EN_UNPAIRED_QUOTES) URL: https://languagetool.org/insights/post/punctuation-guide/#what-are-parentheses Rule: https://community.languagetool.org/rule/show/EN_UNPAIRED_QUOTES?lang=en-US Category: PUNCTUATION
Raw output
modules/10-basics/10-hello-world/en/README.md:40:29: Unpaired symbol: ‘"’ seems to be missing (EN_UNPAIRED_QUOTES)
 URL: https://languagetool.org/insights/post/punctuation-guide/#what-are-parentheses 
 Rule: https://community.languagetool.org/rule/show/EN_UNPAIRED_QUOTES?lang=en-US
 Category: PUNCTUATION
consol.log("it's JavaScript");
console.log('it's JavaScript");
consolelog("it's JavaScript");
```

Even a small difference, for example one extra letter or a different sign, can cause the program not to work. This also applies to case, that is, to the difference between uppercase and lowercase letters. While in ordinary text `Hello` and `hello` look the same, for JavaScript these are different words. JavaScript considers `console.log`, `Console.Log`, and `CONSOLE.LOG` to be different commands, and only the first variant will work.
Expand Down
8 changes: 4 additions & 4 deletions modules/25-strings/20-string-concatenation/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Here is how combining several strings works:

```text
'Hello' + ', ' + 'World!'
└──┬──┘ └┬┘ └──┬───┘
└────┬───┘ │
'Hello, ' + 'World!'
└──────┬───────┘
└──┬──┘ └┬─┘ └──┬───┘
└───┬───┘ │
'Hello, ' + 'World!'
└─────┬──────┘
'Hello, World!'
```

Expand Down
2 changes: 1 addition & 1 deletion modules/35-calling-functions/100-call/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ It's impossible to learn everything - and there's no need to. What matters is kn
- **MDN** ([developer.mozilla.org](https://developer.mozilla.org/en-US/)) - documentation on the built-in features of the language and browser APIs.
- **Node.js documentation** ([nodejs.org/api](https://nodejs.org/api/)) - the server side, functions for working with the file system, the network, and so on.

Another way is to read other people's code: any package on npm is open, and in it you can often find techniques that aren't written about in textbooks.
Another way to learn something new is to read other people's code. The source code of third-party libraries is open, and it often contains techniques that aren't written about in textbooks.
19 changes: 9 additions & 10 deletions modules/35-calling-functions/180-variadic-parameters/en/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

An interesting feature of some functions is the ability to accept a variable number of parameters. This is not about default values. Take a look at this example:

```javascript
Expand All @@ -7,23 +6,23 @@

The `Math.max()` function finds the maximum value among the passed parameters. How many parameters do you think it expects as input? If you open the documentation for this function, you will see a strange construct:

```text
Math.max([value1[, value2[, ...]]])
```
```text
Math.max([value1[, value2[, ...]]])
```

This notation means that this function accepts any number of parameters as input (and can even be called without them). The optionality of the passed parameters is described by the brackets _[ ]_, exactly the same way optional parameters with default values are described. The ability to pass any number of parameters is encoded in this part _[, ...]_.
This notation means that this function accepts any number of parameters as input (and can even be called without them). The optionality of the passed parameters is described by the brackets _[ ]_, exactly the same way optional parameters with default values are described. The ability to pass any number of parameters is encoded in this part _[, ...]_.

```javascript
Math.max(1, -3, 2, 3, 2); // 3
```
```javascript
Math.max(1, -3, 2, 3, 2); // 3
```

Everything specified in square brackets is optional. In this notation `Math.max([value1[, value2[, ...]]])` there are several such brackets, and they are nested within each other. Let's break down each of them:
Everything specified in square brackets is optional. In this notation `Math.max([value1[, value2[, ...]]])` there are several such brackets, and they are nested within each other. Let's break down each of them:

- The first square brackets contain `[value1[, value2[, ...]]]`, which means you can call the function without parameters, since these square brackets contain everything that is passed into the function. If you remove all the contents of these brackets and the brackets themselves, you are left with `Math.max()` — a call without parameters.
- The second square brackets are nested inside the first and contain `[, value2[, ...]]`. They indicate that if we specified the first parameter, then we can optionally specify a second parameter. Without these brackets and their contents, the notation would look like `Math.max([value1])`.
- The third square brackets are nested inside the second and contain `[, ...]`. The ellipsis indicates that there can be any number of parameters. If you remove these brackets and their contents, you get a notation like `Math.max([value1[, value2]])`.

The comma is inside the square brackets because if we do not specify a parameter, the comma is not needed. Otherwise, a call with a single parameter would look like this `Math.max(value1,)`.
The comma is inside the square brackets because if we do not specify a parameter, the comma is not needed. Otherwise, a call with a single parameter would look like this `Math.max(value1,)`.

Check notice on line 25 in modules/35-calling-functions/180-variadic-parameters/en/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/35-calling-functions/180-variadic-parameters/en/README.md#L25

Commas should not be placed before a closing parenthesis. Either move the comma outside of the parentheses, or remove it altogether. (COMMA_CLOSING_PARENTHESIS[1]) Suggestions: `value1),`, `value1)` Rule: https://community.languagetool.org/rule/show/COMMA_CLOSING_PARENTHESIS?lang=en-US&subId=1 Category: PUNCTUATION
Raw output
modules/35-calling-functions/180-variadic-parameters/en/README.md:25:178: Commas should not be placed before a closing parenthesis. Either move the comma outside of the parentheses, or remove it altogether. (COMMA_CLOSING_PARENTHESIS[1])
 Suggestions: `value1),`, `value1)`
 Rule: https://community.languagetool.org/rule/show/COMMA_CLOSING_PARENTHESIS?lang=en-US&subId=1
 Category: PUNCTUATION

The `Math.min()` function works similarly, only it looks for the smallest value:

Expand Down
2 changes: 1 addition & 1 deletion modules/38-objects/100-objects/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ console.log(roundedTemperature); // => '22.9'
(22.93).toFixed(1); // '22.9'
```

_FYI. Technically, it's a bit more complicated. It's not the numbers themselves that have methods, but the data (objects) of the Number type. Numbers written in variables or constants are automatically converted to this type when called, this process is called boxing._
It may seem that the `toFixed()` method belongs to the number itself. In fact, for the duration of the call JavaScript wraps the number in a `Number` object, which has this method. Thanks to this wrapper, methods can be called directly on numbers. The same happens with strings, only the object is called `String`.

Why do we need methods? Why not just use functions? The situation with numbers is even more complicated. Some operations are implemented as methods of numbers, such as `.toFixed()`, and most of them are implemented as methods accessible via `Math`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ It uses a lot of extra characters and the word `return`. Since version ES6, an a
```javascript
// It takes a little time to get used to it,
// but after a while it'll save your life
const double = (x) => x ** 2;
const square = (x) => x ** 2;
```

There are two differences from the full definition, it omits the curly brackets and the `return` statement. The shortened version carries out the return automatically. It means that there is exactly one computable expression inside such a function, and its result will be immediately returned.
Expand Down
2 changes: 1 addition & 1 deletion modules/40-define-functions/470-packages/en/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
As a program grows, it is not only the number of lines of code that increases, but also the number of modules. In small projects you can keep dozens of files side by side, but real applications can have hundreds and thousands of files. On top of that, useful code is something you want to reuse across different projects.

In Python, packages-as-directories are used to group modules. In the JavaScript ecosystem, the unit of reuse and distribution is a **package** (an npm package). A package is a set of modules that is published and installed as a whole.
To handle this, modules are grouped. In the JavaScript ecosystem, the unit of reuse and distribution is a **package** (an npm package). A package is a set of modules that is published and installed as a whole.

Check notice on line 3 in modules/40-define-functions/470-packages/en/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/40-define-functions/470-packages/en/README.md#L3

Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’. (EN_A_VS_AN) Suggestions: `a` URL: https://languagetool.org/insights/post/indefinite-articles/ Rule: https://community.languagetool.org/rule/show/EN_A_VS_AN?lang=en-US Category: MISC
Raw output
modules/40-define-functions/470-packages/en/README.md:3:119: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’. (EN_A_VS_AN)
 Suggestions: `a`
 URL: https://languagetool.org/insights/post/indefinite-articles/ 
 Rule: https://community.languagetool.org/rule/show/EN_A_VS_AN?lang=en-US
 Category: MISC

## What a package is

Expand Down
19 changes: 14 additions & 5 deletions modules/45-logic/70-logical-expressions/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ false || ""; // ''
undefined || ""; // ''
```

We covered the comparison operators `===` and `!==` in one of our lessons, and we mentioned that JavaScript also has the operators `==` and `!=`, though you shouldn't use them. The very difference lies in the type conversion:
For such cases JavaScript has a separate operator, `??`. It also substitutes the right operand for the left one, but it only triggers on `null` and `undefined`. Other falsy values pass through it as ordinary data:

```javascript
0 ?? 100; // 0
"" ?? 100; // ''
null ?? 100; // 100
undefined ?? 100; // 100
```

So when a default value should replace only "nothing", use `??`, and when it should replace any falsy value, use `||`.

Type conversion also explains why JavaScript has two kinds of comparison. Besides the strict operators `===` and `!==`, the language has the loose `==` and `!=`. The difference between them lies exactly in the type conversion:

```javascript
console.log("" === false); // => false
Expand Down Expand Up @@ -92,12 +103,10 @@ value === ("first" || "second");

That's how we picture it in our minds, yet languages work differently, so this kind of code will lead to the wrong result. How do you read it correctly? We have to remember operator priority. The first thing to evaluate is wrapped in parentheses, i.e. `'first' || 'second'`. If we execute this code, the output will be:

```bash
node
'Welcome to Node.js v17.4.0.
```console
$ node
> 'first' || 'second'
'first'
>
```

Now we can substitute the original expression with the partly evaluated one:
Expand Down
4 changes: 2 additions & 2 deletions modules/48-conditionals/30-if/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Here the string `'Yes, it is true'` will be printed because the condition `5 > 3
┌────────────┐
│ condition? │
└─────┬──────┘
true │
│ true
↓
┌────────────┐
│ if body │
│ if body │
└────────────┘
```

Expand Down
17 changes: 9 additions & 8 deletions modules/48-conditionals/40-if-else/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ const getTypeOfSentence = (sentence) => {
We added the keyword `else` and a new block with curly braces. This block runs only if the condition in `if` is false.

```text
┌───────────┐
│ condition?│
└─────┬─────┘
true │ │ false
↓ ↓
┌──────────┐ ┌──────────┐
│ if body │ │ else body│
└──────────┘ └──────────┘
┌────────────┐
│ condition? │
└──────┬─────┘
┌───────┴──────┐
true │ │ false
↓ ↓
┌───────────┐ ┌───────────┐
│ if body │ │ else body │
└───────────┘ └───────────┘
```

## Nested conditions
Expand Down
28 changes: 15 additions & 13 deletions modules/48-conditionals/50-else-if/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ getTypeOfSentence("No!"); // Sentence is exclamation
Now all conditions are arranged into a single construct. `else if` means "if the previous condition was not met, but the current one is".

```text
┌─────────────────┐
│ condition 1? │
└────┬────────┬───┘
true │ │ false
↓ ↓
┌──────────┐ ┌─────────────────┐
│ if body │ │ condition 2? │
└──────────┘ └────┬────────┬───┘
true │ │ false
↓ ↓
┌──────────────┐ ┌────────────┐
│ else if body │ │ else body │
└──────────────┘ └────────────┘
┌──────────────┐
│ condition 1? │
└──────┬───────┘
┌───────┴───────┐
true │ │ false
↓ ↓
┌───────────┐ ┌──────────────┐
│ if body │ │ condition 2? │
└───────────┘ └──────┬───────┘
┌────┴──────────┐
true │ │ false
↓ ↓
┌──────────────┐ ┌───────────┐
│ else if body │ │ else body │
└──────────────┘ └───────────┘
```

The function logic results in the following scheme:
Expand Down
Loading