Skip to content

Commit 57d2887

Browse files
authored
Merge pull request #6 from javascript-tutorial/sync-99e59ba6
Sync with upstream @ 99e59ba
2 parents d41a755 + 65bb2bf commit 57d2887

File tree

64 files changed

+408
-273
lines changed

Some content is hidden

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

64 files changed

+408
-273
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
@@ -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.

1-js/01-getting-started/4-devtools/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To see errors and get a lot of other useful information about scripts, "develope
88

99
Most developers lean towards Chrome or Firefox for development because those browsers have the best developer tools. Other browsers also provide developer tools, sometimes with special features, but are usually playing "catch-up" to Chrome or Firefox. So most developers have a "favorite" browser and switch to others if a problem is browser-specific.
1010

11-
Developer tools are potent; they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
11+
Developer tools are potent, they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
1212

1313
## Google Chrome
1414

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

Lines changed: 1 addition & 1 deletion
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`.

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

Lines changed: 1 addition & 1 deletion
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
```

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

Lines changed: 1 addition & 1 deletion
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.

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

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

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

Lines changed: 27 additions & 14 deletions
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

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

Lines changed: 1 addition & 1 deletion
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

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 7 additions & 5 deletions
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)