Skip to content

Commit a5e3778

Browse files
authored
Merge branch 'master' into master
2 parents 8505d92 + 57d2887 commit a5e3778

File tree

63 files changed

+407
-272
lines changed

Some content is hidden

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

63 files changed

+407
-272
lines changed

Diff for: 1-js/01-getting-started/1-intro/article.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# An Introduction to JavaScript
22

3-
Let's see what's so special about JavaScript, what we can achieve with it, and which other technologies play well with it.
3+
Let's see what's so special about JavaScript, what we can achieve with it, and what other technologies play well with it.
44

55
## What is JavaScript?
66

@@ -116,6 +116,6 @@ There are more. Of course, even if we use one of transpiled languages, we should
116116

117117
## Summary
118118

119-
- JavaScript was initially created as a browser-only language, but is now used in many other environments as well.
120-
- Today, JavaScript has a unique position as the most widely-adopted browser language with full integration with HTML/CSS.
119+
- JavaScript was initially created as a browser-only language, but it is now used in many other environments as well.
120+
- Today, JavaScript has a unique position as the most widely-adopted browser language with full integration in HTML/CSS.
121121
- There are many languages that get "transpiled" to JavaScript and provide certain features. It is recommended to take a look at them, at least briefly, after mastering JavaScript.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -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/Reference/Operators/Bitwise_Operators) when they are needed.
147+
: Bitwise operators work with 32-bit integers at the lowest, bit-level: see the [docs](mdn:/JavaScript/Guide/Expressions_and_Operators#Bitwise) 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`.

Diff for: 1-js/03-code-quality/02-coding-style/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Here's an example of an `.eslintrc` file:
328328
},
329329
"rules": {
330330
"no-console": 0,
331-
"indent": ["warning", 2]
331+
"indent": 2
332332
}
333333
}
334334
```

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Actually, there are two parts in Babel:
2323

2424
2. Second, the polyfill.
2525

26-
New language features may include new built-in functions and syntax constructs.
26+
New language features may include not only syntax constructs, but also built-in functions.
2727
The transpiler rewrites the code, transforming syntax constructs into older ones. But as for new built-in functions, we need to implement them. JavaScript is a highly dynamic language, scripts may add/modify any functions, so that they behave according to the modern standard.
2828

2929
A script that updates/adds new functions is called "polyfill". It "fills in" the gap and adds missing implementations.

Diff for: 1-js/04-object-basics/01-object/8-multiply-numeric/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 3
22

33
---
44

5-
# Multiply numeric properties by 2
5+
# Multiply numeric property values by 2
66

7-
Create a function `multiplyNumeric(obj)` that multiplies all numeric properties of `obj` by `2`.
7+
Create a function `multiplyNumeric(obj)` that multiplies all numeric property values of `obj` by `2`.
88

99
For instance:
1010

Diff for: 1-js/04-object-basics/02-object-copy/article.md

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Object copying, references
1+
# Object references and copying
22

3-
One of the fundamental differences of objects vs primitives is that they are stored and copied "by reference".
3+
One of the fundamental differences of objects versus primitives is that objects are stored and copied "by reference", as opposed to primitive values: strings, numbers, booleans, etc -- that are always copied "as a whole value".
44

5-
Primitive values: strings, numbers, booleans -- are assigned/copied "as a whole value".
5+
That's easy to understand if we look a bit "under a cover" of what happens when we copy a value.
66

7-
For instance:
7+
Let's start with a primitive, such as a string.
8+
9+
Here we put a copy of `message` into `phrase`:
810

911
```js
1012
let message = "Hello!";
@@ -15,21 +17,31 @@ As a result we have two independent variables, each one is storing the string `"
1517

1618
![](variable-copy-value.svg)
1719

20+
Quite an obvious result, right?
21+
1822
Objects are not like that.
1923

20-
**A variable stores not the object itself, but its "address in memory", in other words "a reference" to it.**
24+
**A variable assigned to an object stores not the object itself, but its "address in memory", in other words "a reference" to it.**
2125

22-
Here's the picture for the object:
26+
Let's look at an example of such variable:
2327

2428
```js
2529
let user = {
2630
name: "John"
2731
};
2832
```
2933

34+
And here's how it's actually stored in memory:
35+
3036
![](variable-contains-reference.svg)
3137

32-
Here, the object is stored somewhere in memory. And the variable `user` has a "reference" to it.
38+
The object is stored somewhere in memory (at the right of the picture), while the `user` variable (at the left) has a "reference" to it.
39+
40+
We may think of an object variable, such as `user`, as of a sheet of paper with the address.
41+
42+
When we perform actions with the object, e.g. take a property `user.name`, JavaScript engine looks into that address and performs the operation on the actual object.
43+
44+
Now here's why it's important.
3345

3446
**When an object variable is copied -- the reference is copied, the object is not duplicated.**
3547

@@ -45,6 +57,8 @@ Now we have two variables, each one with the reference to the same object:
4557

4658
![](variable-copy-reference.svg)
4759

60+
As you can see, there's still one object, now with two variables that reference it.
61+
4862
We can use any variable to access the object and modify its contents:
4963

5064
```js run
@@ -59,15 +73,14 @@ admin.name = 'Pete'; // changed by the "admin" reference
5973
alert(*!*user.name*/!*); // 'Pete', changes are seen from the "user" reference
6074
```
6175
62-
The example above demonstrates that there is only one object. As if we had a cabinet with two keys and used one of them (`admin`) to get into it. Then, if we later use another key (`user`) we can see changes.
6376
64-
## Comparison by reference
77+
It's just as if we had a cabinet with two keys and used one of them (`admin`) to get into it. Then, if we later use another key (`user`) we can see changes.
6578
66-
The equality `==` and strict equality `===` operators for objects work exactly the same.
79+
## Comparison by reference
6780
68-
**Two objects are equal only if they are the same object.**
81+
Two objects are equal only if they are the same object.
6982
70-
Here two variables reference the same object, thus they are equal:
83+
For instance, here `a` and `b` reference the same object, thus they are equal:
7184
7285
```js run
7386
let a = {};
@@ -77,7 +90,7 @@ alert( a == b ); // true, both variables reference the same object
7790
alert( a === b ); // true
7891
```
7992
80-
And here two independent objects are not equal, even though both are empty:
93+
And here two independent objects are not equal, even though they look alike (both are empty):
8194
8295
```js run
8396
let a = {};
@@ -86,7 +99,7 @@ let b = {}; // two independent objects
8699
alert( a == b ); // false
87100
```
88101
89-
For comparisons like `obj1 > obj2` or for a comparison against a primitive `obj == 5`, objects are converted to primitives. We'll study how object conversions work very soon, but to tell the truth, such comparisons occur very rarely, usually as a result of a coding mistake.
102+
For comparisons like `obj1 > obj2` or for a comparison against a primitive `obj == 5`, objects are converted to primitives. We'll study how object conversions work very soon, but to tell the truth, such comparisons are needed very rarely, usually they appear as a result of a programming mistake.
90103
91104
## Cloning and merging, Object.assign
92105

Diff for: 1-js/04-object-basics/03-garbage-collection/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Simply put, "reachable" values are those that are accessible or usable somehow.
2323

2424
2. Any other value is considered reachable if it's reachable from a root by a reference or by a chain of references.
2525

26-
For instance, if there's an object in a global variable, and that object has a property referencing another object, that object is considered reachable. And those that it references are also reachable. Detailed examples to follow.
26+
For instance, if there's an object in a global variable, and that object has a property referencing another object, *that* object is considered reachable. And those that it references are also reachable. Detailed examples to follow.
2727

2828
There's a background process in the JavaScript engine that is called [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that have become unreachable.
2929

Diff for: 1-js/04-object-basics/04-object-methods/article.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ user.sayHi = function() {
3232
user.sayHi(); // Hello!
3333
```
3434

35-
Here we've just used a Function Expression to create the function and assign it to the property `user.sayHi` of the object.
35+
Here we've just used a Function Expression to create a function and assign it to the property `user.sayHi` of the object.
3636

37-
Then we can call it. The user can now speak!
37+
Then we can call it as `user.sayHi()`. The user can now speak!
3838

39-
A function that is the property of an object is called its *method*.
39+
A function that is a property of an object is called its *method*.
4040

4141
So, here we've got a method `sayHi` of the object `user`.
4242

@@ -160,14 +160,16 @@ let user = {
160160
let admin = user;
161161
user = null; // overwrite to make things obvious
162162

163-
admin.sayHi(); // Whoops! inside sayHi(), the old name is used! error!
163+
*!*
164+
admin.sayHi(); // TypeError: Cannot read property 'name' of null
165+
*/!*
164166
```
165167

166168
If we used `this.name` instead of `user.name` inside the `alert`, then the code would work.
167169

168170
## "this" is not bound
169171

170-
In JavaScript, keyword `this` behaves unlike most other programming languages. It can be used in any function.
172+
In JavaScript, keyword `this` behaves unlike most other programming languages. It can be used in any function, even if it's not a method of an object.
171173

172174
There's no syntax error in the following example:
173175

0 commit comments

Comments
 (0)