Skip to content

Commit 141fc29

Browse files
authored
feat: update from upstream to 2022-07-13 (#1041)
* feat: update from upstream * feat: update t0 2022-05-22 * feat: update to 2022-06-19 * feat: update to 2022-06 * feat: update to 2022-07 * feat: update to 2022-07-12 * feat: update
1 parent efb9cf7 commit 141fc29

File tree

103 files changed

+479
-319
lines changed

Some content is hidden

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

103 files changed

+479
-319
lines changed

1-js/01-getting-started/1-intro/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ Modern tools make the transpilation very fast and transparent, actually allowing
106106

107107
Examples of such languages:
108108

109-
- [CoffeeScript](http://coffeescript.org/) is a "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
110-
- [TypeScript](http://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
111-
- [Flow](http://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
109+
- [CoffeeScript](https://coffeescript.org/) is a "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
110+
- [TypeScript](https://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
111+
- [Flow](https://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
112112
- [Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google.
113113
- [Brython](https://brython.info/) is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript.
114114
- [Kotlin](https://kotlinlang.org/docs/reference/js-overview.html) is a modern, concise and safe programming language that can target the browser or Node.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
# Manuals and specifications
33

4-
This book is a *tutorial*. It aims to help you gradually learn the language. But once you're familiar with the basics, you'll need other sources.
4+
This book is a *tutorial*. It aims to help you gradually learn the language. But once you're familiar with the basics, you'll need other resources.
55

66
## Specification
77

88
[The ECMA-262 specification](https://www.ecma-international.org/publications/standards/Ecma-262.htm) contains the most in-depth, detailed and formalized information about JavaScript. It defines the language.
99

1010
But being that formalized, it's difficult to understand at first. So if you need the most trustworthy source of information about the language details, the specification is the right place. But it's not for everyday use.
1111

12-
A new specification version is released every year. In-between these releases, the latest specification draft is at <https://tc39.es/ecma262/>.
12+
A new specification version is released every year. Between these releases, the latest specification draft is at <https://tc39.es/ecma262/>.
1313

1414
To read about new bleeding-edge features, including those that are "almost standard" (so-called "stage 3"), see proposals at <https://github.com/tc39/proposals>.
1515

@@ -19,19 +19,19 @@ Also, if you're developing for the browser, then there are other specifications
1919

2020
- **MDN (Mozilla) JavaScript Reference** is the main manual with examples and other information. It's great to get in-depth information about individual language functions, methods etc.
2121

22-
One can find it at <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>.
22+
You can find it at <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>.
2323

24-
Although, it's often best to use an internet search instead. Just use "MDN [term]" in the query, e.g. <https://google.com/search?q=MDN+parseInt> to search for `parseInt` function.
24+
Although, it's often best to use an internet search instead. Just use "MDN [term]" in the query, e.g. <https://google.com/search?q=MDN+parseInt> to search for the `parseInt` function.
2525

2626
## Compatibility tables
2727

2828
JavaScript is a developing language, new features get added regularly.
2929

3030
To see their support among browser-based and other engines, see:
3131

32-
- <http://caniuse.com> - per-feature tables of support, e.g. to see which engines support modern cryptography functions: <http://caniuse.com/#feat=cryptography>.
32+
- <https://caniuse.com> - per-feature tables of support, e.g. to see which engines support modern cryptography functions: <https://caniuse.com/#feat=cryptography>.
3333
- <https://kangax.github.io/compat-table> - a table with language features and engines that support those or don't support.
3434

35-
All these resources are useful in real-life development, as they contain valuable information about language details, their support etc.
35+
All these resources are useful in real-life development, as they contain valuable information about language details, their support, etc.
3636

3737
Please remember them (or this page) for the cases when you need in-depth information about a particular feature.

1-js/01-getting-started/3-code-editors/article.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ An IDE loads the project (which can be many files), allows navigation between fi
1313
If you haven't selected an IDE yet, consider the following options:
1414

1515
- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, free).
16-
- [WebStorm](http://www.jetbrains.com/webstorm/) (cross-platform, paid).
16+
- [WebStorm](https://www.jetbrains.com/webstorm/) (cross-platform, paid).
1717

1818
For Windows, there's also "Visual Studio", not to be confused with "Visual Studio Code". "Visual Studio" is a paid and mighty Windows-only editor, well-suited for the .NET platform. It's also good at JavaScript. There's also a free version [Visual Studio Community](https://www.visualstudio.com/vs/community/).
1919

@@ -31,7 +31,6 @@ In practice, lightweight editors may have a lot of plugins including directory-l
3131

3232
The following options deserve your attention:
3333

34-
- [Atom](https://atom.io/) (cross-platform, free).
3534
- [Sublime Text](http://www.sublimetext.com) (cross-platform, shareware).
3635
- [Notepad++](https://notepad-plus-plus.org/) (Windows, free).
3736
- [Vim](http://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ let message = 'Hello';
6464
```
6565

6666
Some people also define multiple variables in this multiline style:
67+
6768
```js no-beautify
6869
let user = 'John',
6970
age = 25,
@@ -103,6 +104,7 @@ For instance, the variable `message` can be imagined as a box labeled `"message"
103104
We can put any value in the box.
104105
105106
We can also change it as many times as we want:
107+
106108
```js run
107109
let message;
108110
@@ -192,7 +194,7 @@ let my-name; // hyphens '-' aren't allowed in the name
192194
```
193195

194196
```smart header="Case matters"
195-
Variables named `apple` and `AppLE` are two different variables.
197+
Variables named `apple` and `APPLE` are two different variables.
196198
```
197199

198200
````smart header="Non-Latin letters are allowed, but not recommended"
@@ -260,7 +262,6 @@ myBirthday = '01.01.2001'; // error, can't reassign the constant!
260262
261263
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.
262264
263-
264265
### Uppercase constants
265266
266267
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known prior to execution.
@@ -291,13 +292,14 @@ When should we use capitals for a constant and when should we name it normally?
291292
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.
292293
293294
For instance:
295+
294296
```js
295297
const pageLoadTime = /* time taken by a webpage to load */;
296298
```
297299
298300
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.
299301
300-
In other words, capital-named constants are only used as aliases for "hard-coded" values.
302+
In other words, capital-named constants are only used as aliases for "hard-coded" values.
301303
302304
## Name things right
303305

1-js/02-first-steps/05-types/article.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,20 @@ We'll see more about working with numbers in the chapter <info:number>.
6868
6969
## BigInt [#bigint-type]
7070
71-
In JavaScript, the "number" type cannot represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives. It's a technical limitation caused by their internal representation.
71+
In JavaScript, the "number" type cannot safely represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives.
7272

73-
For most purposes that's quite enough, but sometimes we need really big numbers, e.g. for cryptography or microsecond-precision timestamps.
73+
To be really precise, the "number" type can store larger integers (up to <code>1.7976931348623157 * 10<sup>308</sup></code>), but outside of the safe integer range <code>±(2<sup>53</sup>-1)</code> there'll be a precision error, because not all digits fit into the fixed 64-bit storage. So an "approximate" value may be stored.
74+
75+
For example, these two numbers (right above the safe range) are the same:
76+
77+
```js
78+
console.log(9007199254740991 + 1); // 9007199254740992
79+
console.log(9007199254740991 + 2); // 9007199254740992
80+
```
81+
82+
So to say, all odd integers greater than <code>(2<sup>53</sup>-1)</code> can't be stored at all in the "number" type.
83+
84+
For most purposes <code>±(2<sup>53</sup>-1)</code> range is quite enough, but sometimes we need the entire range of really big integers, e.g. for cryptography or microsecond-precision timestamps.
7485

7586
`BigInt` type was recently added to the language to represent integers of arbitrary length.
7687

@@ -263,14 +274,16 @@ Some people prefer `typeof(x)`, although the `typeof x` syntax is much more comm
263274
264275
There are 8 basic data types in JavaScript.
265276
266-
- `number` for numbers of any kind: integer or floating-point, integers are limited by <code>±(2<sup>53</sup>-1)</code>.
267-
- `bigint` is for integer numbers of arbitrary length.
268-
- `string` for strings. A string may have zero or more characters, there's no separate single-character type.
269-
- `boolean` for `true`/`false`.
270-
- `null` for unknown values -- a standalone type that has a single value `null`.
271-
- `undefined` for unassigned values -- a standalone type that has a single value `undefined`.
272-
- `object` for more complex data structures.
273-
- `symbol` for unique identifiers.
277+
- Seven primitive data types:
278+
- `number` for numbers of any kind: integer or floating-point, integers are limited by <code>±(2<sup>53</sup>-1)</code>.
279+
- `bigint` for integer numbers of arbitrary length.
280+
- `string` for strings. A string may have zero or more characters, there's no separate single-character type.
281+
- `boolean` for `true`/`false`.
282+
- `null` for unknown values -- a standalone type that has a single value `null`.
283+
- `undefined` for unassigned values -- a standalone type that has a single value `undefined`.
284+
- `symbol` for unique identifiers.
285+
- And one non-primitive data type:
286+
- `object` for more complex data structures.
274287
275288
The `typeof` operator allows us to see which type is stored in a variable.
276289
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The answer: `null`, because it's the first falsy value from the list.
22

33
```js run
4-
alert( 1 && null && 2 );
4+
alert(1 && null && 2);
55
```
66

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ For example, outputting goods from a list one after another or just running the
66

77
*Loops* are a way to repeat the same code multiple times.
88

9+
```smart header="The for..of and for..in loops"
10+
A small announcement for advanced readers.
11+
12+
This article covers only basic loops: `while`, `do..while` and `for(..;..;..)`.
13+
14+
If you came to this article searching for other types of loops, here are the pointers:
15+
16+
- See [for..in](info:object#forin) to loop over object properties.
17+
- See [for..of](info:array#loops) and [iterables](info:iterable) for looping over arrays and iterable objects.
18+
19+
Otherwise, please read on.
20+
```
21+
922
## The "while" loop
1023

1124
The `while` loop has the following syntax:
@@ -162,10 +175,8 @@ for (i = 0; i < 3; i++) { // use an existing variable
162175
163176
alert(i); // 3, visible, because declared outside of the loop
164177
```
165-
166178
````
167179

168-
169180
### Skipping parts
170181

171182
Any part of `for` can be skipped.
@@ -268,7 +279,7 @@ for (let i = 0; i < 10; i++) {
268279

269280
From a technical point of view, this is identical to the example above. Surely, we can just wrap the code in an `if` block instead of using `continue`.
270281

271-
But as a side-effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of `if` is longer than a few lines, that may decrease the overall readability.
282+
But as a side effect, this created one more level of nesting (the `alert` call inside the curly braces). If the code inside of `if` is longer than a few lines, that may decrease the overall readability.
272283
````
273284
274285
````warn header="No `break/continue` to the right side of '?'"
@@ -286,7 +297,6 @@ if (i > 5) {
286297
287298
...and rewrite it using a question mark:
288299
289-
290300
```js no-beautify
291301
(i > 5) ? alert(i) : *!*continue*/!*; // continue isn't allowed here
292302
```
@@ -321,6 +331,7 @@ We need a way to stop the process if the user cancels the input.
321331
The ordinary `break` after `input` would only break the inner loop. That's not sufficient -- labels, come to the rescue!
322332

323333
A *label* is an identifier with a colon before a loop:
334+
324335
```js
325336
labelName: for (...) {
326337
...
@@ -342,6 +353,7 @@ The `break <labelName>` statement in the loop below breaks out to the label:
342353
// do something with the value...
343354
}
344355
}
356+
345357
alert('Done!');
346358
```
347359

@@ -362,13 +374,15 @@ The `continue` directive can also be used with a label. In this case, code execu
362374
Labels do not allow us to jump into an arbitrary place in the code.
363375
364376
For example, it is impossible to do this:
377+
365378
```js
366379
break label; // jump to the label below (doesn't work)
367380
368381
label: for (...)
369382
```
370383
371384
A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.:
385+
372386
```js
373387
label: {
374388
// ...

1-js/02-first-steps/14-switch/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ switch (a) {
139139
140140
Now both `3` and `5` show the same message.
141141
142-
The ability to "group" cases is a side-effect of how `switch/case` works without `break`. Here the execution of `case 3` starts from the line `(*)` and goes through `case 5`, because there's no `break`.
142+
The ability to "group" cases is a side effect of how `switch/case` works without `break`. Here the execution of `case 3` starts from the line `(*)` and goes through `case 5`, because there's no `break`.
143143
144144
## Type matters
145145

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ function name(parameters, delimited, by, comma) {
522522
523523
To make the code clean and easy to understand, it's recommended to use mainly local variables and parameters in the function, not outer variables.
524524
525-
It is always easier to understand a function which gets parameters, works with them and returns a result than a function which gets no parameters, but modifies outer variables as a side-effect.
525+
It is always easier to understand a function which gets parameters, works with them and returns a result than a function which gets no parameters, but modifies outer variables as a side effect.
526526
527527
Function naming:
528528

1-js/02-first-steps/16-function-expressions/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Everything would work the same.
9090

9191

9292
````smart header="Why is there a semicolon at the end?"
93-
You might wonder, why does Function Expression have a semicolon `;` at the end, but Function Declaration does not:
93+
You might wonder, why do Function Expressions have a semicolon `;` at the end, but Function Declarations do not:
9494
9595
```js
9696
function sayHi() {
@@ -144,13 +144,13 @@ function showCancel() {
144144
ask("Do you agree?", showOk, showCancel);
145145
```
146146

147-
In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such function usually draws a nice-looking question window. But that's another story.
147+
In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such functions usually draw a nice-looking question window. But that's another story.
148148

149149
**The arguments `showOk` and `showCancel` of `ask` are called *callback functions* or just *callbacks*.**
150150

151151
The idea is that we pass a function and expect it to be "called back" later if necessary. In our case, `showOk` becomes the callback for "yes" answer, and `showCancel` for "no" answer.
152152

153-
We can use Function Expressions to write the same function much shorter:
153+
We can use Function Expressions to write an equivalent, shorter function:
154154

155155
```js run no-beautify
156156
function ask(question, yes, no) {
@@ -186,7 +186,7 @@ Let's formulate the key differences between Function Declarations and Expression
186186

187187
First, the syntax: how to differentiate between them in the code.
188188

189-
- *Function Declaration:* a function, declared as a separate statement, in the main code flow.
189+
- *Function Declaration:* a function, declared as a separate statement, in the main code flow:
190190

191191
```js
192192
// Function Declaration

0 commit comments

Comments
 (0)