Skip to content

Commit 25a7820

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-34a80e70
2 parents 9b9f6d8 + 34a80e7 commit 25a7820

70 files changed

Lines changed: 2124 additions & 361 deletions

File tree

Some content is hidden

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

.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: 15 additions & 15 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
@@ -151,11 +151,11 @@ So, we should declare a variable once and then refer to it without `let`.
151151
````
152152

153153
```smart header="Functional languages"
154-
It's interesting to note that there exist [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](https://www.scala-lang.org/) or [Erlang](https://www.erlang.org/) that forbid changing variable values.
154+
It's interesting to note that there exist so-called [pure functional](https://en.wikipedia.org/wiki/Purely_functional_programming) programming languages, such as [Haskell](https://en.wikipedia.org/wiki/Haskell), that forbid changing variable values.
155155
156156
In such languages, once the value is stored "in the box", it's there forever. If we need to store something else, the language forces us to create a new box (declare a new variable). We can't reuse the old one.
157157
158-
Though it may seem a little odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation confers certain benefits. Studying such a language (even if you're not planning to use it soon) is recommended to broaden the mind.
158+
Though it may seem a little odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation confers certain benefits.
159159
```
160160

161161
## Variable naming [#variable-naming]
@@ -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/02-first-steps/05-types/article.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ const bigInt = 1234567890123456789012345678901234567890n;
9494

9595
As `BigInt` numbers are rarely needed, we don't cover them here, but devoted them a separate chapter <info:bigint>. Read it when you need such big numbers.
9696
97-
98-
```smart header="Compatibility issues"
99-
Right now, `BigInt` is supported in Firefox/Chrome/Edge/Safari, but not in IE.
100-
```
101-
102-
You can check [*MDN* BigInt compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) to know which versions of a browser are supported.
103-
10497
## String
10598
10699
A string in JavaScript must be surrounded by quotes.
@@ -224,7 +217,7 @@ The `symbol` type is used to create unique identifiers for objects. We have to m
224217

225218
## The typeof operator [#type-typeof]
226219

227-
The `typeof` operator returns the type of the argument. It's useful when we want to process values of different types differently or just want to do a quick check.
220+
The `typeof` operator returns the type of the operand. It's useful when we want to process values of different types differently or just want to do a quick check.
228221

229222
A call to `typeof x` returns a string with the type name:
230223

1-js/02-first-steps/07-type-conversions/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes
3434

3535
## Numeric Conversion
3636

37-
Numeric conversion happens in mathematical functions and expressions automatically.
37+
Numeric conversion in mathematical functions and expressions happens automatically.
3838

3939
For example, when division `/` is applied to non-numbers:
4040

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ The result of `a % b` is the [remainder](https://en.wikipedia.org/wiki/Remainder
5050
For instance:
5151

5252
```js run
53-
alert( 5 % 2 ); // 1, a remainder of 5 divided by 2
54-
alert( 8 % 3 ); // 2, a remainder of 8 divided by 3
53+
alert( 5 % 2 ); // 1, the remainder of 5 divided by 2
54+
alert( 8 % 3 ); // 2, the remainder of 8 divided by 3
55+
alert( 8 % 4 ); // 0, the remainder of 8 divided by 4
5556
```
5657

5758
### Exponentiation **
@@ -68,7 +69,7 @@ alert( 2 ** 3 ); // 2³ = 8
6869
alert( 2 ** 4 ); // 2⁴ = 16
6970
```
7071

71-
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
72+
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
7273

7374
For example, a square root is an exponentiation by ½:
7475

@@ -305,7 +306,7 @@ let n = 2;
305306
306307
n *= 3 + 5; // right part evaluated first, same as n *= 8
307308
308-
alert( n ); // 16
309+
alert( n ); // 16
309310
```
310311

311312
## Increment/decrement

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if (cond) {
6868

6969
## The "else" clause
7070

71-
The `if` statement may contain an optional "else" block. It executes when the condition is falsy.
71+
The `if` statement may contain an optional `else` block. It executes when the condition is falsy.
7272

7373
For example:
7474
```js run
@@ -181,9 +181,9 @@ alert( message );
181181
It may be difficult at first to grasp what's going on. But after a closer look, we can see that it's just an ordinary sequence of tests:
182182

183183
1. The first question mark checks whether `age < 3`.
184-
2. If true -- it returns `'Hi, baby!'`. Otherwise, it continues to the expression after the colon '":"', checking `age < 18`.
185-
3. If that's true -- it returns `'Hello!'`. Otherwise, it continues to the expression after the next colon '":"', checking `age < 100`.
186-
4. If that's true -- it returns `'Greetings!'`. Otherwise, it continues to the expression after the last colon '":"', returning `'What an unusual age!'`.
184+
2. If true -- it returns `'Hi, baby!'`. Otherwise, it continues to the expression after the colon ":", checking `age < 18`.
185+
3. If that's true -- it returns `'Hello!'`. Otherwise, it continues to the expression after the next colon ":", checking `age < 100`.
186+
4. If that's true -- it returns `'Greetings!'`. Otherwise, it continues to the expression after the last colon ":", returning `'What an unusual age!'`.
187187

188188
Here's how this looks using `if..else`:
189189

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Here's the example with `user` assigned to a name:
3737
```js run
3838
let user = "John";
3939

40-
alert(user ?? "Anonymous"); // John (user is not null/udefined)
40+
alert(user ?? "Anonymous"); // John (user is not null/undefined)
4141
```
4242
4343
We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`.
@@ -76,7 +76,7 @@ alert(firstName || lastName || nickName || "Anonymous"); // Supercoder
7676
*/!*
7777
```
7878
79-
Historically, the OR `||` operator was there first. It exists since the beginning of JavaScript, so developers were using it for such purposes for a long time.
79+
Historically, the OR `||` operator was there first. It's been there since the beginning of JavaScript, so developers were using it for such purposes for a long time.
8080
8181
On the other hand, the nullish coalescing operator `??` was added to JavaScript only recently, and the reason for that was that people weren't quite happy with `||`.
8282

1-js/02-first-steps/18-javascript-specials/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ More in: <info:variables> and <info:types>.
103103

104104
We're using a browser as a working environment, so basic UI functions will be:
105105

106-
[`prompt(question, [default])`](mdn:api/Window/prompt)
106+
[`prompt(question, [default])`](https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt)
107107
: Ask a `question`, and return either what the visitor entered or `null` if they clicked "cancel".
108108

109-
[`confirm(question)`](mdn:api/Window/confirm)
109+
[`confirm(question)`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm)
110110
: Ask a `question` and suggest to choose between Ok and Cancel. The choice is returned as `true/false`.
111111

112-
[`alert(message)`](mdn:api/Window/alert)
112+
[`alert(message)`](https://developer.mozilla.org/en-US/docs/Web/API/Window/alert)
113113
: Output a `message`.
114114

115115
All these functions are *modal*, they pause the code execution and prevent the visitor from interacting with the page until they answer.
@@ -144,7 +144,7 @@ Assignments
144144
: There is a simple assignment: `a = b` and combined ones like `a *= 2`.
145145

146146
Bitwise
147-
: Bitwise operators work with 32-bit integers at the lowest, bit-level: see the [docs](mdn:/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) when they are needed.
147+
: Bitwise operators work with 32-bit integers at the lowest, bit-level: see the [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) when they are needed.
148148

149149
Conditional
150150
: The only operator with three parameters: `cond ? resultA : resultB`. If `cond` is truthy, returns `resultA`, otherwise `resultB`.

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

Lines changed: 2 additions & 3 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

@@ -73,7 +73,6 @@ JavaScript is a highly dynamic language. Scripts may add/modify any function, ev
7373
7474
Two interesting polyfill libraries are:
7575
- [core js](https://github.com/zloirock/core-js) that supports a lot, allows to include only needed features.
76-
- [polyfill.io](https://polyfill.io/) service that provides a script with polyfills, depending on the features and user's browser.
7776
7877
7978
## Summary
@@ -85,7 +84,7 @@ Just don't forget to use a transpiler (if using modern syntax or operators) and
8584
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.
8685
8786
Good resources that show the current state of support for various features:
88-
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.
87+
- <https://compat-table.github.io/compat-table/es6/> - for pure JavaScript.
8988
- <https://caniuse.com/> - for browser-related functions.
9089
9190
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.

0 commit comments

Comments
 (0)