Skip to content

Commit 9604c06

Browse files
Merge branch 'master' into patch-1
2 parents 058be77 + c151e11 commit 9604c06

File tree

44 files changed

+2017
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2017
-234
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: iliakan

1-js/02-first-steps/04-variables/article.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ In older scripts, you may also find another keyword: `var` instead of `let`:
8888
*!*var*/!* message = 'Hello';
8989
```
9090

91-
The `var` keyword is *almost* the same as `let`. It also declares a variable, but in a slightly different, "old-school" way.
91+
The `var` keyword is *almost* the same as `let`. It also declares a variable but in a slightly different, "old-school" way.
9292

93-
There are subtle differences between `let` and `var`, but they do not matter for us yet. We'll cover them in detail in the chapter <info:var>.
93+
There are subtle differences between `let` and `var`, but they do not matter to us yet. We'll cover them in detail in the chapter <info:var>.
9494
````
9595
9696
## A real-life analogy
9797
9898
We can easily grasp the concept of a "variable" if we imagine it as a "box" for data, with a uniquely-named sticker on it.
9999
100-
For instance, the variable `message` can be imagined as a box labeled `"message"` with the value `"Hello!"` in it:
100+
For instance, the variable `message` can be imagined as a box labelled `"message"` with the value `"Hello!"` in it:
101101
102102
![](variable.svg)
103103
@@ -198,14 +198,14 @@ Variables named `apple` and `APPLE` are two different variables.
198198
```
199199

200200
````smart header="Non-Latin letters are allowed, but not recommended"
201-
It is possible to use any language, including cyrillic letters, Chinese logograms and so on, like this:
201+
It is possible to use any language, including Cyrillic letters, Chinese logograms and so on, like this:
202202
203203
```js
204204
let имя = '...';
205205
let 我 = '...';
206206
```
207207
208-
Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it some time.
208+
Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it sometime.
209209
````
210210

211211
````warn header="Reserved names"
@@ -260,11 +260,11 @@ const myBirthday = '18.04.1982';
260260
myBirthday = '01.01.2001'; // error, can't reassign the constant!
261261
```
262262
263-
When a programmer is sure that a variable will never change, they can declare it with `const` to guarantee and clearly communicate that fact to everyone.
263+
When a programmer is sure that a variable will never change, they can declare it with `const` to guarantee and communicate that fact to everyone.
264264
265265
### Uppercase constants
266266
267-
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known prior to execution.
267+
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known before execution.
268268
269269
Such constants are named using capital letters and underscores.
270270
@@ -289,15 +289,15 @@ Benefits:
289289
290290
When should we use capitals for a constant and when should we name it normally? Let's make that clear.
291291
292-
Being a "constant" just means that a variable's value never changes. But there are constants that are known prior to execution (like a hexadecimal value for red) and there are constants that are *calculated* in run-time, during the execution, but do not change after their initial assignment.
292+
Being a "constant" just means that a variable's value never changes. But some constants are known before execution (like a hexadecimal value for red) and some constants are *calculated* in run-time, during the execution, but do not change after their initial assignment.
293293
294294
For instance:
295295
296296
```js
297297
const pageLoadTime = /* time taken by a webpage to load */;
298298
```
299299
300-
The value of `pageLoadTime` is not known prior to the page load, so it's named normally. But it's still a constant because it doesn't change after assignment.
300+
The value of `pageLoadTime` is not known before the page load, so it's named normally. But it's still a constant because it doesn't change after the assignment.
301301
302302
In other words, capital-named constants are only used as aliases for "hard-coded" values.
303303
@@ -307,18 +307,18 @@ Talking about variables, there's one more extremely important thing.
307307
308308
A variable name should have a clean, obvious meaning, describing the data that it stores.
309309
310-
Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code was written by a beginner versus an experienced developer.
310+
Variable naming is one of the most important and complex skills in programming. A glance at variable names can reveal which code was written by a beginner versus an experienced developer.
311311
312-
In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch. When we return to some code after doing something else for a while, it's much easier to find information that is well-labeled. Or, in other words, when the variables have good names.
312+
In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch. When we return to some code after doing something else for a while, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names.
313313
314314
Please spend time thinking about the right name for a variable before declaring it. Doing so will repay you handsomely.
315315
316316
Some good-to-follow rules are:
317317
318318
- Use human-readable names like `userName` or `shoppingCart`.
319-
- Stay away from abbreviations or short names like `a`, `b`, `c`, unless you really know what you're doing.
319+
- Stay away from abbreviations or short names like `a`, `b`, and `c`, unless you know what you're doing.
320320
- Make names maximally descriptive and concise. Examples of bad names are `data` and `value`. Such names say nothing. It's only okay to use them if the context of the code makes it exceptionally obvious which data or value the variable is referencing.
321-
- Agree on terms within your team and in your own mind. If a site visitor is called a "user" then we should name related variables `currentUser` or `newUser` instead of `currentVisitor` or `newManInTown`.
321+
- Agree on terms within your team and in your mind. If a site visitor is called a "user" then we should name related variables `currentUser` or `newUser` instead of `currentVisitor` or `newManInTown`.
322322
323323
Sounds simple? Indeed it is, but creating descriptive and concise variable names in practice is not. Go for it.
324324

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Teams behind JavaScript engines have their own ideas about what to implement fir
77

88
So it's quite common for an engine to implement only part of the standard.
99

10-
A good page to see the current state of support for language features is <https://kangax.github.io/compat-table/es6/> (it's big, we have a lot to study yet).
10+
A good page to see the current state of support for language features is <https://compat-table.github.io/compat-table/es6/> (it's big, we have a lot to study yet).
1111

1212
As programmers, we'd like to use most recent features. The more good stuff - the better!
1313

@@ -85,7 +85,7 @@ Just don't forget to use a transpiler (if using modern syntax or operators) and
8585
For example, later when you're familiar with JavaScript, you can setup a code build system based on [webpack](https://webpack.js.org/) with the [babel-loader](https://github.com/babel/babel-loader) plugin.
8686
8787
Good resources that show the current state of support for various features:
88-
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.
88+
- <https://compat-table.github.io/compat-table/es6/> - for pure JavaScript.
8989
- <https://caniuse.com/> - for browser-related functions.
9090
9191
P.S. Google Chrome is usually the most up-to-date with language features, try it if a tutorial demo fails. Most tutorial demos work with any modern browser though.

1-js/04-object-basics/04-object-methods/8-chain-calls/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 2
44

55
# Chaining
66

7-
There's a `ladder` object that allows to go up and down:
7+
There's a `ladder` object that allows you to go up and down:
88

99
```js
1010
let ladder = {
@@ -21,7 +21,7 @@ let ladder = {
2121
};
2222
```
2323

24-
Now, if we need to make several calls in sequence, can do it like this:
24+
Now, if we need to make several calls in sequence, we can do it like this:
2525

2626
```js
2727
ladder.up();
@@ -32,10 +32,10 @@ ladder.down();
3232
ladder.showStep(); // 0
3333
```
3434

35-
Modify the code of `up`, `down` and `showStep` to make the calls chainable, like this:
35+
Modify the code of `up`, `down`, and `showStep` to make the calls chainable, like this:
3636

3737
```js
3838
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
3939
```
4040

41-
Such approach is widely used across JavaScript libraries.
41+
Such an approach is widely used across JavaScript libraries.

1-js/04-object-basics/09-object-toprimitive/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ let obj = {
253253
}
254254
};
255255

256-
alert(obj + 2); // 22 ("2" + 2), conversion to primitive returned a string => concatenation
256+
alert(obj + 2); // "22" ("2" + 2), conversion to primitive returned a string => concatenation
257257
```
258258

259259
## Summary

1-js/05-data-types/02-number/article.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ In modern JavaScript, there are two types of numbers:
44

55
1. Regular numbers in JavaScript are stored in 64-bit format [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754), also known as "double precision floating point numbers". These are numbers that we're using most of the time, and we'll talk about them in this chapter.
66

7-
2. BigInt numbers represent integers of arbitrary length. They are sometimes needed because a regular integer number can't safely exceed <code>(2<sup>53</sup>-1)</code> or be less than <code>-(2<sup>53</sup>-1)</code>, as we mentioned earlier in the chapter <info:types>. As bigints are used in few special areas, we devote them a special chapter <info:bigint>.
7+
2. BigInt numbers represent integers of arbitrary length. They are sometimes needed because a regular integer number can't safely exceed <code>(2<sup>53</sup>-1)</code> or be less than <code>-(2<sup>53</sup>-1)</code>, as we mentioned earlier in the chapter <info:types>. As bigints are used in a few special areas, we devote them to a special chapter <info:bigint>.
88

99
So here we'll talk about regular numbers. Let's expand our knowledge of them.
1010

@@ -41,7 +41,7 @@ In other words, `e` multiplies the number by `1` with the given zeroes count.
4141
1.23e6 === 1.23 * 1000000; // e6 means *1000000
4242
```
4343

44-
Now let's write something very small. Say, 1 microsecond (one millionth of a second):
44+
Now let's write something very small. Say, 1 microsecond (one-millionth of a second):
4545

4646
```js
4747
let mсs = 0.000001;
@@ -103,13 +103,13 @@ alert( num.toString(16) ); // ff
103103
alert( num.toString(2) ); // 11111111
104104
```
105105

106-
The `base` can vary from `2` to `36`. By default it's `10`.
106+
The `base` can vary from `2` to `36`. By default, it's `10`.
107107

108108
Common use cases for this are:
109109

110110
- **base=16** is used for hex colors, character encodings etc, digits can be `0..9` or `A..F`.
111111
- **base=2** is mostly for debugging bitwise operations, digits can be `0` or `1`.
112-
- **base=36** is the maximum, digits can be `0..9` or `A..Z`. The whole latin alphabet is used to represent a number. A funny, but useful case for `36` is when we need to turn a long numeric identifier into something shorter, for example to make a short url. Can simply represent it in the numeral system with base `36`:
112+
- **base=36** is the maximum, digits can be `0..9` or `A..Z`. The whole Latin alphabet is used to represent a number. A funny, but useful case for `36` is when we need to turn a long numeric identifier into something shorter, for example, to make a short url. Can simply represent it in the numeral system with base `36`:
113113

114114
```js run
115115
alert( 123456..toString(36) ); // 2n9c
@@ -188,7 +188,7 @@ There are two ways to do so:
188188
alert( num.toFixed(5) ); // "12.34000", added zeroes to make exactly 5 digits
189189
```
190190

191-
We can convert it to a number using the unary plus or a `Number()` call, e.g write `+num.toFixed(5)`.
191+
We can convert it to a number using the unary plus or a `Number()` call, e.g. write `+num.toFixed(5)`.
192192

193193
## Imprecise calculations
194194

@@ -222,7 +222,13 @@ But why does this happen?
222222

223223
A number is stored in memory in its binary form, a sequence of bits - ones and zeroes. But fractions like `0.1`, `0.2` that look simple in the decimal numeric system are actually unending fractions in their binary form.
224224

225-
What is `0.1`? It is one divided by ten `1/10`, one-tenth. In decimal numeral system such numbers are easily representable. Compare it to one-third: `1/3`. It becomes an endless fraction `0.33333(3)`.
225+
```js run
226+
alert(0.1.toString(2)); // 0.0001100110011001100110011001100110011001100110011001101
227+
alert(0.2.toString(2)); // 0.001100110011001100110011001100110011001100110011001101
228+
alert((0.1 + 0.2).toString(2)); // 0.0100110011001100110011001100110011001100110011001101
229+
```
230+
231+
What is `0.1`? It is one divided by ten `1/10`, one-tenth. In the decimal numeral system, such numbers are easily representable. Compare it to one-third: `1/3`. It becomes an endless fraction `0.33333(3)`.
226232

227233
So, division by powers `10` is guaranteed to work well in the decimal system, but division by `3` is not. For the same reason, in the binary numeral system, the division by powers of `2` is guaranteed to work, but `1/10` becomes an endless binary fraction.
228234

@@ -242,7 +248,7 @@ That's why `0.1 + 0.2` is not exactly `0.3`.
242248
```smart header="Not only JavaScript"
243249
The same issue exists in many other programming languages.
244250

245-
PHP, Java, C, Perl, Ruby give exactly the same result, because they are based on the same numeric format.
251+
PHP, Java, C, Perl, and Ruby give exactly the same result, because they are based on the same numeric format.
246252
```
247253

248254
Can we work around the problem? Sure, the most reliable method is to round the result with the help of a method [toFixed(n)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed):
@@ -266,7 +272,7 @@ alert( (0.1 * 10 + 0.2 * 10) / 10 ); // 0.3
266272
alert( (0.28 * 100 + 0.14 * 100) / 100); // 0.4200000000000001
267273
```
268274

269-
So, multiply/divide approach reduces the error, but doesn't remove it totally.
275+
So, the multiply/divide approach reduces the error, but doesn't remove it totally.
270276

271277
Sometimes we could try to evade fractions at all. Like if we're dealing with a shop, then we can store prices in cents instead of dollars. But what if we apply a discount of 30%? In practice, totally evading fractions is rarely possible. Just round them to cut "tails" when needed.
272278

@@ -288,7 +294,7 @@ Another funny consequence of the internal representation of numbers is the exist
288294

289295
That's because a sign is represented by a single bit, so it can be set or not set for any number including a zero.
290296

291-
In most cases the distinction is unnoticeable, because operators are suited to treat them as the same.
297+
In most cases, the distinction is unnoticeable, because operators are suited to treat them as the same.
292298
```
293299

294300
## Tests: isFinite and isNaN
@@ -337,7 +343,7 @@ Please note that an empty or a space-only string is treated as `0` in all numeri
337343
````smart header="`Number.isNaN` and `Number.isFinite`"
338344
[Number.isNaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN) and [Number.isFinite](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite) methods are the more "strict" versions of `isNaN` and `isFinite` functions. They do not autoconvert their argument into a number, but check if it belongs to the `number` type instead.
339345

340-
- `Number.isNaN(value)` returns `true` if the argument belongs to the `number` type and it is `NaN`. In any other case it returns `false`.
346+
- `Number.isNaN(value)` returns `true` if the argument belongs to the `number` type and it is `NaN`. In any other case, it returns `false`.
341347

342348
```js run
343349
alert( Number.isNaN(NaN) ); // true
@@ -348,7 +354,7 @@ Please note that an empty or a space-only string is treated as `0` in all numeri
348354
alert( isNaN("str") ); // true, because isNaN converts string "str" into a number and gets NaN as a result of this conversion
349355
```
350356

351-
- `Number.isFinite(value)` returns `true` if the argument belongs to the `number` type and it is not `NaN/Infinity/-Infinity`. In any other case it returns `false`.
357+
- `Number.isFinite(value)` returns `true` if the argument belongs to the `number` type and it is not `NaN/Infinity/-Infinity`. In any other case, it returns `false`.
352358

353359
```js run
354360
alert( Number.isFinite(123) ); // true
@@ -367,7 +373,7 @@ In a way, `Number.isNaN` and `Number.isFinite` are simpler and more straightforw
367373
There is a special built-in method `Object.is` that compares values like `===`, but is more reliable for two edge cases:
368374

369375
1. It works with `NaN`: `Object.is(NaN, NaN) === true`, that's a good thing.
370-
2. Values `0` and `-0` are different: `Object.is(0, -0) === false`, technically that's correct, because internally the number has a sign bit that may be different even if all other bits are zeroes.
376+
2. Values `0` and `-0` are different: `Object.is(0, -0) === false`, technically that's correct because internally the number has a sign bit that may be different even if all other bits are zeroes.
371377

372378
In all other cases, `Object.is(a, b)` is the same as `a === b`.
373379

@@ -385,7 +391,7 @@ alert( +"100px" ); // NaN
385391

386392
The sole exception is spaces at the beginning or at the end of the string, as they are ignored.
387393

388-
But in real life we often have values in units, like `"100px"` or `"12pt"` in CSS. Also in many countries the currency symbol goes after the amount, so we have `"19€"` and would like to extract a numeric value out of that.
394+
But in real life, we often have values in units, like `"100px"` or `"12pt"` in CSS. Also in many countries, the currency symbol goes after the amount, so we have `"19€"` and would like to extract a numeric value out of that.
389395

390396
That's what `parseInt` and `parseFloat` are for.
391397

@@ -479,4 +485,4 @@ For fractions:
479485

480486
More mathematical functions:
481487

482-
- See the [Math](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math) object when you need them. The library is very small, but can cover basic needs.
488+
- See the [Math](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Math) object when you need them. The library is very small but can cover basic needs.

1-js/05-data-types/03-string/3-truncate/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The result of the function should be the truncated (if needed) string.
1111
For instance:
1212

1313
```js
14-
truncate("What I'd like to tell on this topic is:", 20) = "What I'd like to te…"
14+
truncate("What I'd like to tell on this topic is:", 20) == "What I'd like to te…"
1515

16-
truncate("Hi everyone!", 20) = "Hi everyone!"
16+
truncate("Hi everyone!", 20) == "Hi everyone!"
1717
```

0 commit comments

Comments
 (0)