Skip to content

Commit 19cd4ab

Browse files
committed
up
1 parent 85e67eb commit 19cd4ab

File tree

12 files changed

+56
-59
lines changed

12 files changed

+56
-59
lines changed

1-js/05-data-types/11-date/article.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ To create a new `Date` object call `new Date()` with one of the following argume
2929
alert( Jan02_1970 );
3030
```
3131

32-
The number of milliseconds that has passed since the beginning of 1970 is called a *timestamp*.
32+
An integer number representing the number of milliseconds that has passed since the beginning of 1970 is called a *timestamp*.
3333

3434
It's a lightweight numeric representation of a date. We can always create a date from a timestamp using `new Date(timestamp)` and convert the existing `Date` object to a timestamp using the `date.getTime()` method (see below).
3535

3636
`new Date(datestring)`
37-
: If there is a single argument, and it's a string, then it is parsed with the `Date.parse` algorithm (see below).
38-
37+
: If there is a single argument, and it's a string, then it is parsed automatically. The algorithm is the same as `Date.parse` uses, we'll cover it later.
3938

4039
```js run
4140
let date = new Date("2017-01-26");
@@ -131,12 +130,12 @@ Besides the given methods, there are two special ones that do not have a UTC-var
131130

132131
The following methods allow to set date/time components:
133132

134-
- [`setFullYear(year [, month, date])`](mdn:js/Date/setFullYear)
135-
- [`setMonth(month [, date])`](mdn:js/Date/setMonth)
133+
- [`setFullYear(year, [month], [date])`](mdn:js/Date/setFullYear)
134+
- [`setMonth(month, [date])`](mdn:js/Date/setMonth)
136135
- [`setDate(date)`](mdn:js/Date/setDate)
137-
- [`setHours(hour [, min, sec, ms])`](mdn:js/Date/setHours)
138-
- [`setMinutes(min [, sec, ms])`](mdn:js/Date/setMinutes)
139-
- [`setSeconds(sec [, ms])`](mdn:js/Date/setSeconds)
136+
- [`setHours(hour, [min], [sec], [ms])`](mdn:js/Date/setHours)
137+
- [`setMinutes(min, [sec], [ms])`](mdn:js/Date/setMinutes)
138+
- [`setSeconds(sec, [ms])`](mdn:js/Date/setSeconds)
140139
- [`setMilliseconds(ms)`](mdn:js/Date/setMilliseconds)
141140
- [`setTime(milliseconds)`](mdn:js/Date/setTime) (sets the whole date by milliseconds since 01.01.1970 UTC)
142141

@@ -318,7 +317,7 @@ As a result, the first benchmark will have less CPU resources than the second. T
318317
319318
**For more reliable benchmarking, the whole pack of benchmarks should be rerun multiple times.**
320319
321-
Here's the code example:
320+
For example, like this:
322321
323322
```js run
324323
function diffSubtract(date1, date2) {
@@ -424,4 +423,4 @@ alert(`Loading started ${performance.now()}ms ago`);
424423
// more than 3 digits after the decimal point are precision errors, but only the first 3 are correct
425424
```
426425

427-
Node.js has `microtime` module and other ways. Technically, any device and environment allows to get more precision, it's just not in `Date`.
426+
Node.js has `microtime` module and other ways. Technically, almost any device and environment allows to get more precision, it's just not in `Date`.

1-js/05-data-types/12-json/2-serialize-event-circular/task.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
In simple cases of circular references, we can exclude an offending property from serialization by its name.
88

9-
But sometimes there are many backreferences. And names may be used both in circular references and normal properties.
9+
But sometimes we can't just use the name, as it may be used both in circular references and normal properties. So we can check the property by its value.
1010

1111
Write `replacer` function to stringify everything, but remove properties that reference `meetup`:
1212

@@ -22,7 +22,7 @@ let meetup = {
2222
};
2323

2424
*!*
25-
// circular references
25+
// circular references
2626
room.occupiedBy = meetup;
2727
meetup.self = meetup;
2828
*/!*
@@ -39,4 +39,3 @@ alert( JSON.stringify(meetup, function replacer(key, value) {
3939
}
4040
*/
4141
```
42-

1-js/05-data-types/12-json/article.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let user = {
2121
alert(user); // {name: "John", age: 30}
2222
```
2323

24-
...But in the process of development, new properties are added, old properties are renamed and removed. Updating such `toString` every time can become a pain. We could try to loop over properties in it, but what if the object is complex and has nested objects in properties? We'd need to implement their conversion as well. And, if we're sending the object over a network, then we also need to supply the code to "read" our object on the receiving side.
24+
...But in the process of development, new properties are added, old properties are renamed and removed. Updating such `toString` every time can become a pain. We could try to loop over properties in it, but what if the object is complex and has nested objects in properties? We'd need to implement their conversion as well.
2525

2626
Luckily, there's no need to write the code to handle all this. The task has been solved already.
2727

@@ -76,7 +76,7 @@ Please note that a JSON-encoded object has several important differences from th
7676

7777
`JSON.stringify` can be applied to primitives as well.
7878

79-
Natively supported JSON types are:
79+
JSON supports following data types:
8080

8181
- Objects `{ ... }`
8282
- Arrays `[ ... ]`
@@ -100,7 +100,7 @@ alert( JSON.stringify(true) ); // true
100100
alert( JSON.stringify([1, 2, 3]) ); // [1,2,3]
101101
```
102102

103-
JSON is data-only cross-language specification, so some JavaScript-specific object properties are skipped by `JSON.stringify`.
103+
JSON is data-only language-independent specification, so some JavaScript-specific object properties are skipped by `JSON.stringify`.
104104

105105
Namely:
106106

@@ -213,9 +213,9 @@ alert( JSON.stringify(meetup, *!*['title', 'participants']*/!*) );
213213
// {"title":"Conference","participants":[{},{}]}
214214
```
215215

216-
Here we are probably too strict. The property list is applied to the whole object structure. So participants are empty, because `name` is not in the list.
216+
Here we are probably too strict. The property list is applied to the whole object structure. So the objects in `participants` are empty, because `name` is not in the list.
217217

218-
Let's include every property except `room.occupiedBy` that would cause the circular reference:
218+
Let's include in the list every property except `room.occupiedBy` that would cause the circular reference:
219219

220220
```js run
221221
let room = {
@@ -244,7 +244,7 @@ Now everything except `occupiedBy` is serialized. But the list of properties is
244244

245245
Fortunately, we can use a function instead of an array as the `replacer`.
246246

247-
The function will be called for every `(key, value)` pair and should return the "replaced" value, which will be used instead of the original one.
247+
The function will be called for every `(key, value)` pair and should return the "replaced" value, which will be used instead of the original one. Or `undefined` if the value is to be skipped.
248248

249249
In our case, we can return `value` "as is" for everything except `occupiedBy`. To ignore `occupiedBy`, the code below returns `undefined`:
250250

@@ -262,7 +262,7 @@ let meetup = {
262262
room.occupiedBy = meetup; // room references meetup
263263

264264
alert( JSON.stringify(meetup, function replacer(key, value) {
265-
alert(`${key}: ${value}`); // to see what replacer gets
265+
alert(`${key}: ${value}`);
266266
return (key == 'occupiedBy') ? undefined : value;
267267
}));
268268

@@ -283,7 +283,7 @@ Please note that `replacer` function gets every key/value pair including nested
283283

284284
The first call is special. It is made using a special "wrapper object": `{"": meetup}`. In other words, the first `(key, value)` pair has an empty key, and the value is the target object as a whole. That's why the first line is `":[object Object]"` in the example above.
285285

286-
The idea is to provide as much power for `replacer` as possible: it has a chance to analyze and replace/skip the whole object if necessary.
286+
The idea is to provide as much power for `replacer` as possible: it has a chance to analyze and replace/skip even the whole object if necessary.
287287

288288

289289
## Formatting: spacer
@@ -393,7 +393,7 @@ alert( JSON.stringify(meetup) );
393393
*/
394394
```
395395

396-
As we can see, `toJSON` is used both for the direct call `JSON.stringify(room)` and for the nested object.
396+
As we can see, `toJSON` is used both for the direct call `JSON.stringify(room)` and when `room` is nested is another encoded object.
397397

398398

399399
## JSON.parse
@@ -402,7 +402,7 @@ To decode a JSON-string, we need another method named [JSON.parse](mdn:js/JSON/p
402402

403403
The syntax:
404404
```js
405-
let value = JSON.parse(str[, reviver]);
405+
let value = JSON.parse(str, [reviver]);
406406
```
407407

408408
str
@@ -432,7 +432,7 @@ user = JSON.parse(user);
432432
alert( user.friends[1] ); // 1
433433
```
434434

435-
The JSON may be as complex as necessary, objects and arrays can include other objects and arrays. But they must obey the format.
435+
The JSON may be as complex as necessary, objects and arrays can include other objects and arrays. But they must obey the same JSON format.
436436

437437
Here are typical mistakes in hand-written JSON (sometimes we have to write it for debugging purposes):
438438

@@ -481,7 +481,7 @@ Whoops! An error!
481481

482482
The value of `meetup.date` is a string, not a `Date` object. How could `JSON.parse` know that it should transform that string into a `Date`?
483483

484-
Let's pass to `JSON.parse` the reviving function that returns all values "as is", but `date` will become a `Date`:
484+
Let's pass to `JSON.parse` the reviving function as the second argument, that returns all values "as is", but `date` will become a `Date`:
485485

486486
```js run
487487
let str = '{"title":"Conference","date":"2017-11-30T12:00:00.000Z"}';

1-js/06-advanced-functions/01-recursion/article.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,18 @@ In other words, a company has departments.
326326
327327
Now let's say we want a function to get the sum of all salaries. How can we do that?
328328
329-
An iterative approach is not easy, because the structure is not simple. The first idea may be to make a `for` loop over `company` with nested subloop over 1st level departments. But then we need more nested subloops to iterate over the staff in 2nd level departments like `sites`. ...And then another subloop inside those for 3rd level departments that might appear in the future? Should we stop on level 3 or make 4 levels of loops? If we put 3-4 nested subloops in the code to traverse a single object, it becomes rather ugly.
329+
An iterative approach is not easy, because the structure is not simple. The first idea may be to make a `for` loop over `company` with nested subloop over 1st level departments. But then we need more nested subloops to iterate over the staff in 2nd level departments like `sites`... And then another subloop inside those for 3rd level departments that might appear in the future? If we put 3-4 nested subloops in the code to traverse a single object, it becomes rather ugly.
330330
331331
Let's try recursion.
332332
333333
As we can see, when our function gets a department to sum, there are two possible cases:
334334
335-
1. Either it's a "simple" department with an *array of people* -- then we can sum the salaries in a simple loop.
336-
2. Or it's *an object with `N` subdepartments* -- then we can make `N` recursive calls to get the sum for each of the subdeps and combine the results.
335+
1. Either it's a "simple" department with an *array* of people -- then we can sum the salaries in a simple loop.
336+
2. Or it's *an object* with `N` subdepartments -- then we can make `N` recursive calls to get the sum for each of the subdeps and combine the results.
337337
338-
The (1) is the base of recursion, the trivial case.
338+
The 1st case is the base of recursion, the trivial case, when we get an array.
339339
340-
The (2) is the recursive step. A complex task is split into subtasks for smaller departments. They may in turn split again, but sooner or later the split will finish at (1).
340+
The 2nd case when we gen an object is the recursive step. A complex task is split into subtasks for smaller departments. They may in turn split again, but sooner or later the split will finish at (1).
341341
342342
The algorithm is probably even easier to read from the code:
343343

1-js/06-advanced-functions/02-rest-parameters-spread-operator/article.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For instance:
88
- `Object.assign(dest, src1, ..., srcN)` -- copies properties from `src1..N` into `dest`.
99
- ...and so on.
1010

11-
In this chapter we'll learn how to do the same. And, more importantly, how to feel comfortable working with such functions and arrays.
11+
In this chapter we'll learn how to do the same. And also, how to pass arrays to such functions as parameters.
1212

1313
## Rest parameters `...`
1414

@@ -96,9 +96,7 @@ showName("Julius", "Caesar");
9696
showName("Ilya");
9797
```
9898

99-
In old times, rest parameters did not exist in the language, and using `arguments` was the only way to get all arguments of the function, no matter their total number.
100-
101-
And it still works, we can use it today.
99+
In old times, rest parameters did not exist in the language, and using `arguments` was the only way to get all arguments of the function. And it still works, we can find it in the old code.
102100

103101
But the downside is that although `arguments` is both array-like and iterable, it's not an array. It does not support array methods, so we can't call `arguments.map(...)` for example.
104102

@@ -119,9 +117,10 @@ function f() {
119117

120118
f(1); // 1
121119
```
122-
````
123120

124121
As we remember, arrow functions don't have their own `this`. Now we know they don't have the special `arguments` object either.
122+
````
123+
125124
126125
## Spread operator [#spread-operator]
127126

1-js/06-advanced-functions/03-closure/8-make-army/lexenv-makearmy.svg

+4-4
Loading

1-js/06-advanced-functions/03-closure/article.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The Lexical Environment object consists of two parts:
7070
1. *Environment Record* -- an object that stores all local variables as its properties (and some other information like the value of `this`).
7171
2. A reference to the *outer lexical environment*, the one associated with the outer code.
7272

73-
**So, a "variable" is just a property of the special internal object, `Environment Record`. "To get or change a variable" means "to get or change a property of that object".**
73+
**A "variable" is just a property of the special internal object, `Environment Record`. "To get or change a variable" means "to get or change a property of that object".**
7474

7575
For instance, in this simple code, there is only one Lexical Environment:
7676

@@ -80,7 +80,7 @@ This is a so-called global Lexical Environment, associated with the whole script
8080

8181
On the picture above, the rectangle means Environment Record (variable store) and the arrow means the outer reference. The global Lexical Environment has no outer reference, so it points to `null`.
8282

83-
Here's the bigger picture of what happens when a `let` changes:
83+
And that's how it changes when a variable is defined and assigned:
8484

8585
![lexical environment](lexical-environment-global-2.svg)
8686

@@ -119,7 +119,7 @@ Now let's go on and explore what happens when a function accesses an outer varia
119119

120120
During the call, `say()` uses the outer variable `phrase`, let's look at the details of what's going on.
121121

122-
First, when a function runs, a new function Lexical Environment is created automatically. That's a general rule for all functions. That Lexical Environment is used to store local variables and parameters of the call.
122+
When a function runs, a new Lexical Environment is created automatically to store local variables and parameters of the call.
123123

124124
For instance, for `say("John")`, it looks like this (the execution is at the line, labelled with an arrow):
125125

1-js/06-advanced-functions/03-closure/lexenv-nested-makecounter-2.svg

+4-4
Loading

1-js/06-advanced-functions/03-closure/lexenv-nested-makecounter-4.svg

+2-2
Loading

0 commit comments

Comments
 (0)