Skip to content

Sync with upstream @ e1a3f634 #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 173 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
9bae8fd
Typos
peachesontour Sep 21, 2020
2b8354b
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
7c12746
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
74526b4
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
e0db058
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
ed497e7
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
2be35c9
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
443af20
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
f25dca8
Update 7-animation/2-css-animations/article.md
peachesontour Sep 22, 2020
6c37da4
Update 7-animation/2-css-animations/article.md
peachesontour Sep 23, 2020
5168eaa
Update 7-animation/2-css-animations/article.md
peachesontour Sep 23, 2020
689392e
Fix my typos in 1.5.5
vsemozhetbyt Oct 11, 2020
104bee3
Clarify a bit ambiguous wording in 1.5.7
vsemozhetbyt Oct 12, 2020
7faa49e
Symmetrize Map and Set summaries
vsemozhetbyt Oct 12, 2020
154bf02
Fix possible typo in 1.5.7 task
vsemozhetbyt Oct 12, 2020
0be77b0
Clarify some things in 1.5.12
vsemozhetbyt Oct 15, 2020
f0c55ba
FIX: change ; to ,
leviding Oct 15, 2020
fe3ba11
OPT: change "false" to "falsy"
leviding Oct 15, 2020
d6f98e1
Fix a possible typo in 1.6.1
vsemozhetbyt Oct 15, 2020
187e8e1
Fix a typo in 1.6.1 task solution
vsemozhetbyt Oct 15, 2020
de8cf9f
FIX: delete extra space
leviding Oct 17, 2020
2f822c8
Fix semicolons in 1.11.1 (Introduction: callbacks)
vsemozhetbyt Oct 30, 2020
c3979cd
Fix typo.
odsantos Oct 31, 2020
0b6cfc9
Update article.md
johnjacobkenny Oct 31, 2020
1236996
Fix a typo in 1.11.3 (Promises chaining)
vsemozhetbyt Oct 31, 2020
d5a88b6
Fix semicolons in 1.11.6 (Promisification)
vsemozhetbyt Oct 31, 2020
37c6a31
Fix semicolons, remove old note in 1.11.8
vsemozhetbyt Oct 31, 2020
58d9f75
Fix typo in 1.11.6 (Promisification)
vsemozhetbyt Nov 1, 2020
0bdf17e
Fix Optional chaining doc
satyambnsal Nov 1, 2020
05dfb56
Fix typo, add note in 1.12.2 (Async iteration)
vsemozhetbyt Nov 1, 2020
ec81513
Change `var` to `let` in 7.16 regexp-sticky
wam Nov 1, 2020
4e9a335
Correct comment in 1.13.1
vsemozhetbyt Nov 1, 2020
b83f2d7
Fix typos in 'Proxy and Reflect'
vsemozhetbyt Nov 4, 2020
422ef44
Fix outdated note in 1.99.04 (Reference Type)
vsemozhetbyt Nov 5, 2020
e25caae
Correct solution explanation in 1.99.04 (Reference Type)
vsemozhetbyt Nov 5, 2020
bf3c878
Fix link in 2.1.5 (Node properties...)
vsemozhetbyt Nov 5, 2020
b589f38
Merge pull request #2210 from leviding/patch-27
iliakan Nov 9, 2020
9e99c36
Merge pull request #2249 from vsemozhetbyt/patch-9
iliakan Nov 9, 2020
bd23930
Update article.md
leviding Nov 9, 2020
8f91294
Fix typos in 2.1.4 (Searching elements)
vsemozhetbyt Nov 9, 2020
a914bad
fix typo in 06-promisify article.md
ZhaoMuwei Nov 10, 2020
27f6935
Merge pull request #2250 from odsantos/fix-regexp-char-class-typo
iliakan Nov 10, 2020
fd6861e
Merge pull request #2251 from johnjacobkenny/patch-1
iliakan Nov 10, 2020
12a5cb0
Merge pull request #2252 from vsemozhetbyt/patch-10
iliakan Nov 10, 2020
ca9a022
Revert "Fix a typo in 1.11.3 (Promises chaining)"
iliakan Nov 10, 2020
032e18b
Merge pull request #2278 from javascript-tutorial/revert-2252-patch-10
iliakan Nov 10, 2020
2ff5eeb
Merge pull request #2255 from vsemozhetbyt/patch-11
iliakan Nov 10, 2020
48b111d
Merge pull request #2257 from vsemozhetbyt/1.11.8
iliakan Nov 10, 2020
96b9854
Merge pull request #2258 from vsemozhetbyt/patch-12
iliakan Nov 10, 2020
f782e9c
Merge pull request #2259 from satyambnsal/master
iliakan Nov 10, 2020
eba2280
Merge pull request #2260 from vsemozhetbyt/patch-13
iliakan Nov 10, 2020
21d44a0
Merge pull request #2261 from wam/change-var-to-let-in-regexp-sticky-…
iliakan Nov 10, 2020
e9a528f
Merge pull request #2262 from vsemozhetbyt/patch-14
iliakan Nov 10, 2020
bbe7e05
Merge pull request #2266 from vsemozhetbyt/1.99.1
iliakan Nov 10, 2020
876fded
Merge pull request #2270 from vsemozhetbyt/patch-15
iliakan Nov 10, 2020
2f4c29c
Merge pull request #2271 from vsemozhetbyt/patch-16
iliakan Nov 10, 2020
26b393a
Merge pull request #2272 from vsemozhetbyt/patch-17
iliakan Nov 10, 2020
a4194ce
look like ninja code
lumosmind Nov 10, 2020
211db88
Fix typo in 2.1.6 (Attributes and properties)
vsemozhetbyt Nov 10, 2020
59a2f34
Fix a typo in 1.11.3 (Promises chaining)
vsemozhetbyt Nov 10, 2020
7cb6387
Merge pull request #2281 from vsemozhetbyt/patch-10
iliakan Nov 11, 2020
29a7b66
Update article.md
iliakan Nov 11, 2020
fab613d
Merge pull request #2280 from vsemozhetbyt/patch-11
iliakan Nov 11, 2020
fd08e1c
Merge pull request #2279 from lumosmind/patch-53
iliakan Nov 11, 2020
22cf4b6
Merge pull request #2277 from ZhaoMuwei/patch-1
iliakan Nov 11, 2020
5607c77
Merge pull request #2276 from vsemozhetbyt/patch-18
iliakan Nov 11, 2020
5d7cba3
Merge pull request #2275 from leviding/patch-30
iliakan Nov 11, 2020
32d4f13
Merge pull request #2205 from vsemozhetbyt/patch-8
iliakan Nov 11, 2020
ad4bd59
Merge pull request #2204 from vsemozhetbyt/patch-7
iliakan Nov 11, 2020
611236f
Merge pull request #2203 from leviding/patch-25
iliakan Nov 11, 2020
331fafd
Merge pull request #2202 from leviding/patch-24
iliakan Nov 11, 2020
6df0982
FIX: minor typo error
leviding Nov 13, 2020
806e371
Update article.md
leviding Nov 13, 2020
fb43e39
Update article.md
leviding Nov 13, 2020
d977582
Update article.md
leviding Nov 13, 2020
ee2bc1c
Update article.md
leviding Nov 13, 2020
26d449c
Minor grammar alteration.
joneskj55 Nov 13, 2020
99e59ba
Update article.md
iliakan Nov 15, 2020
7a67741
Update article.md
leviding Nov 15, 2020
75e10e2
Update article.md
leviding Nov 15, 2020
cb62d6d
Update article.md
leviding Nov 15, 2020
a39f437
Update article.md
leviding Nov 15, 2020
5b63e81
Update article.md
leviding Nov 15, 2020
358c389
Update article.md
leviding Nov 15, 2020
80eb70f
Update article.md
leviding Nov 15, 2020
adf83c6
Update article.md
leviding Nov 15, 2020
9b3b10f
Update README.md
leviding Nov 16, 2020
6db57d9
Update article.md
leviding Nov 16, 2020
891495c
Promise.any
lumosmind Nov 17, 2020
15780b3
Update task.md
leviding Nov 17, 2020
a81bb4a
Fix typo in 2.2.5 (Dispatching custom events)
vsemozhetbyt Nov 17, 2020
149f63e
FIX: minor typo error, missing "alert( "
leviding Nov 18, 2020
1ba96d4
missssing
joaquinelio Nov 18, 2020
5aeb8fe
Update article.md
leviding Nov 18, 2020
ee8f6d1
Update article.md
joaquinelio Nov 18, 2020
3709b0b
Update article.md
leviding Nov 18, 2020
cd052d1
Update article.md
leviding Nov 18, 2020
0437d57
Fix typo in 2.3.3 (Moving the mouse...)
vsemozhetbyt Nov 18, 2020
5e9937a
Rephrase sentence.
odsantos Nov 18, 2020
0b401e6
Updated article.md
patrikbego Nov 19, 2020
565fef8
Include missing fileServer
manjufy Nov 19, 2020
fa4b19e
Rephrased for better clarity.
patrikbego Nov 19, 2020
1feed09
Rephrased for clarity.
patrikbego Nov 19, 2020
e289aba
Update 1-js/11-async/05-promise-api/article.md
lumosmind Nov 20, 2020
0bdacaf
Fis typo in 2.5.2 (Scripts: async, defer)
vsemozhetbyt Nov 22, 2020
2f0c37d
fixes
iliakan Nov 22, 2020
23da191
minor fixes
iliakan Nov 22, 2020
3cb134f
Merge pull request #2307 from vsemozhetbyt/patch-11
iliakan Nov 23, 2020
bd44850
fix nested markdown
joaquinelio Nov 24, 2020
1e590d6
Merge pull request #2310 from joaquinelio/patch-3
iliakan Nov 24, 2020
58136cb
Update article.md
paroche Nov 24, 2020
dcb3758
Merge pull request #2311 from javascript-tutorial/paroche-patch-20
paroche Nov 24, 2020
865c329
Further minor changes to punctuation and wording
paroche Nov 24, 2020
ac92672
And a little more
paroche Nov 24, 2020
54378cb
Correct subhead in 3.1 (Popups and window methods)
vsemozhetbyt Nov 24, 2020
246c6c4
Merge branch 'master' into patch-1
iliakan Nov 24, 2020
501adfd
Merge pull request #2187 from vsemozhetbyt/patch-1
iliakan Nov 24, 2020
c066fea
Merge pull request #2191 from vsemozhetbyt/patch-2
iliakan Nov 24, 2020
50a20d1
Merge pull request #2298 from manjufy/patch-1
iliakan Nov 24, 2020
f7b2208
Fix typo in 2.3.1 (Mouse events)
vsemozhetbyt Nov 17, 2020
b7a7e68
Fix typo in 2.99.2 (Selection and Range)
vsemozhetbyt Nov 23, 2020
a9d2363
Merge pull request #2296 from odsantos/update-strings
iliakan Nov 24, 2020
dd02130
Merge pull request #2295 from vsemozhetbyt/patch-10
iliakan Nov 24, 2020
aacdf01
Merge pull request #2192 from vsemozhetbyt/patch-3
iliakan Nov 24, 2020
7211729
Merge pull request #2193 from vsemozhetbyt/patch-4
iliakan Nov 24, 2020
445d2c8
minor fixes
iliakan Nov 24, 2020
79710c4
Update article.md
patrikbego Nov 24, 2020
50c3e3d
Merge pull request #2199 from vsemozhetbyt/patch-6
iliakan Nov 25, 2020
9700f82
Merge pull request #2283 from leviding/patch-31
iliakan Nov 25, 2020
47ca608
Update README.md
iliakan Nov 25, 2020
31d9441
Update README.md
iliakan Nov 25, 2020
865174e
Merge pull request #2285 from joneskj55/patch-1
iliakan Nov 25, 2020
b8fb9d4
Merge pull request #2300 from patrikbego/patch-1
iliakan Nov 25, 2020
a2494a7
Merge pull request #2290 from vsemozhetbyt/patch-7
iliakan Nov 25, 2020
fbe2050
Merge pull request #2291 from vsemozhetbyt/patch-8
iliakan Nov 25, 2020
ba277aa
Merge pull request #2292 from joaquinelio/patch-2
iliakan Nov 25, 2020
0e79e06
example is fixed and summary is extended
lumosmind Nov 25, 2020
5f04058
Summary section is fixed
lumosmind Nov 25, 2020
2554d3d
Merge pull request #2293 from leviding/patch-33
iliakan Nov 25, 2020
b73c2a4
typo
lumosmind Nov 25, 2020
947afdd
Merge pull request #2297 from patrikbego/patch-2
iliakan Nov 25, 2020
36c0702
Merge pull request #2309 from vsemozhetbyt/patch-11
iliakan Nov 25, 2020
b3974b3
Merge pull request #2313 from vsemozhetbyt/patch-12
iliakan Nov 25, 2020
193e174
Fix possible typos in 4.1 (ArrayBuffer, binary arrays)
vsemozhetbyt Nov 25, 2020
a0b0d43
Merge pull request #2315 from vsemozhetbyt/patch-1
iliakan Nov 25, 2020
0eef950
minor fixes
iliakan Nov 25, 2020
0ac7894
minor fixes
iliakan Nov 25, 2020
fee6657
minor fixes
iliakan Nov 25, 2020
6ec4c4f
minor fixes
iliakan Nov 25, 2020
91da65d
Fix typos in 4.3 (Blob)
vsemozhetbyt Nov 25, 2020
2793f33
Fix typo in 5.2 (FormData)
vsemozhetbyt Nov 26, 2020
ae6f990
Add missing parenthesis in 5.6 (Fetch API)
vsemozhetbyt Nov 27, 2020
b79964a
Fix typos in 5.8 (XMLHttpRequest)
vsemozhetbyt Nov 28, 2020
513d36e
Expand a note in 5.8 (XMLHttpRequest)
vsemozhetbyt Nov 28, 2020
0f0a0c5
Replace deprecated property in 5.9 (Resumable file upload)
vsemozhetbyt Nov 28, 2020
c828fe3
Fix typo in 5.11 (WebSocket)
vsemozhetbyt Nov 29, 2020
e558805
fixes #2326
iliakan Nov 29, 2020
d2ebb42
Merge pull request #2288 from lumosmind/patch-54
iliakan Nov 29, 2020
b852cfe
Update article.md
joaquinelio Nov 29, 2020
ebd774d
Update 7-animation/2-css-animations/article.md
iliakan Nov 29, 2020
00f138c
Merge pull request #2140 from peachesontour/patch-14
iliakan Nov 29, 2020
6f7d9cf
minor fixes
iliakan Nov 29, 2020
8e6ace0
Merge pull request #2325 from vsemozhetbyt/patch-7
iliakan Nov 29, 2020
59c5400
Merge pull request #2324 from vsemozhetbyt/p5.9
iliakan Nov 29, 2020
277374f
Merge pull request #2323 from vsemozhetbyt/patch-6
iliakan Nov 29, 2020
4697b7b
Merge pull request #2322 from vsemozhetbyt/patch-5
iliakan Nov 29, 2020
8b98721
Merge pull request #2321 from vsemozhetbyt/patch-4
iliakan Nov 29, 2020
d05bbe0
Merge pull request #2320 from vsemozhetbyt/patch-3
iliakan Nov 29, 2020
574dd84
closes #2319
iliakan Nov 29, 2020
361c702
Merge pull request #2316 from vsemozhetbyt/patch-2
iliakan Nov 29, 2020
9065fd3
Merge pull request #2302 from patrikbego/patch-3
iliakan Nov 29, 2020
e1a3f63
Merge pull request #2327 from joaquinelio/patch-4
iliakan Nov 29, 2020
aef401b
merging all conflicts
iliakan Nov 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 1-js/01-getting-started/1-intro/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,20 @@

ऐसी भाषाओं के उदाहरण:

<<<<<<< HEAD
- [CoffeeScript](http://coffeescript.org/) यह जावास्क्रिप्ट के लिए "सिंटैक्टिक शुगर" है। यह छोटे वाक्यविन्यास का परिचय देता है, जिससे हमें स्पष्ट और अधिक सटीक कोड लिखने की अनुमति मिलती है। आमतौर पर, Ruby (रूबी) डेवलपर इसे पसंद करते हैं।
- [TypeScript](http://www.typescriptlang.org/) यह जटिल प्रणालियों के विकास और समर्थन को आसान बनाने के लिए "सख्त डेटा टाइपिंग" को जोड़ने पर केंद्रित है। यह Microsoft द्वारा विकसित किया गया है।
- [Flow](http://flow.org/) यह डेटा टाइपिंग भी जोड़ता है, लेकिन एक अलग तरीके से। Facebook द्वारा विकसित।
- [Dart](https://www.dartlang.org/) यह एक स्वतंत्र भाषा है जिसका अपना इंजन है जो गैर-ब्राउज़र वातावरण (जैसे मोबाइल ऐप) में चलता है, लेकिन इसे जावास्क्रिप्ट पर भी रूपांतरित किया जा सकता है। Google द्वारा विकसित किया गया।
और भी कई हैं। बेशक, भले ही हम रूपांतरित भाषाओं में से एक का उपयोग करें, हमें यह भी जानना चाहिए कि हम वास्तव में क्या कर रहे हैं, यह समझने के लिए जावास्क्रिप्ट जानना महत्वपूर्ण है।
- [Brython](https://brython.info/) यह जावास्क्रिप्ट के लिए एक पायथन ट्रांसपिलर है जो जावास्क्रिप्ट के बिना शुद्ध पायथन में एप्लिकेशन लिखने में सक्षम बनाता है।
=======
- [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.
- [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.
- [Flow](http://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
- [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.
- [Brython](https://brython.info/) is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript.
>>>>>>> e1a3f634a47c119cf1ec7420c49fc0fc7172c0b5

## सारांश

Expand Down
4 changes: 4 additions & 0 deletions 1-js/01-getting-started/4-devtools/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

अधिकांश डेवलपर विकास के लिए क्रोम या फ़ायरफ़ॉक्स की ओर झुकते हैं क्योंकि उन ब्राउज़र में सबसे अच्छा डेवलपर टूल होता है। अन्य ब्राउज़र भी डेवलपर उपकरण प्रदान करते हैं, कभी-कभी विशेष सुविधाओं के साथ, लेकिन आमतौर पर क्रोम या फ़ायरफ़ॉक्स के करीब नहीं होते हैं। इसलिए अधिकांश डेवलपर्स के पास "पसंदीदा" ब्राउज़र होता है और यदि कोई समस्या ब्राउज़र-विशिष्ट है तो ही दूसरों का उपयोग करता है।

<<<<<<< HEAD
डेवलपर उपकरण शक्तिशाली हैं; उनकी कई विशेषताएं हैं। शुरू करने के लिए, हम सीखेंगे कि उन्हें कैसे खोलें, त्रुटियों को देखें और जावास्क्रिप्ट कमांड चलाएं।
=======
Developer tools are potent, they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands.
>>>>>>> e1a3f634a47c119cf1ec7420c49fc0fc7172c0b5

## गूगल क्रोम (Google Chrome)

Expand Down
6 changes: 6 additions & 0 deletions 1-js/02-first-steps/01-hello-world/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

जावास्क्रिप्ट प्रोग्रामों को HTML दस्तावेज़ के किसी भी भाग में `<script>` टैग की सहायता से डाला जा सकता है।

<<<<<<< HEAD
उदाहरण के लिए:
=======
JavaScript programs can be inserted almost anywhere into an HTML document using the `<script>` tag.

For instance:
>>>>>>> e1a3f634a47c119cf1ec7420c49fc0fc7172c0b5

```html run height=100
<!DOCTYPE HTML>
Expand Down
24 changes: 0 additions & 24 deletions 1-js/04-object-basics/01-object/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,6 @@ let user = {
```
That is called a "trailing" or "hanging" comma. Makes it easier to add/remove/move around properties, because all lines become alike.

````smart header="Object with const can be changed"
Please note: an object declared as `const` *can* be modified.

For instance:

```js run
const user = {
name: "John"
};

*!*
user.name = "Pete"; // (*)
*/!*

alert(user.name); // Pete
```

It might seem that the line `(*)` would cause an error, but no. The `const` fixes the value of `user`, but not its contents.

The `const` would give an error only if we try to set `user=...` as a whole.

There's another way to make constant object properties, we'll cover it later in the chapter <info:property-descriptors>.
````

## Square brackets

For multiword properties, the dot access doesn't work:
Expand Down
59 changes: 41 additions & 18 deletions 1-js/04-object-basics/02-object-copy/article.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Object references and copying

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".
One of the fundamental differences of objects versus primitives is that objects are stored and copied "by reference", whereas primitive values: strings, numbers, booleans, etc -- are always copied "as a whole value".

That's easy to understand if we look a bit "under a cover" of what happens when we copy a value.
That's easy to understand if we look a bit under the hood of what happens when we copy a value.

Let's start with a primitive, such as a string.

Expand All @@ -13,17 +13,17 @@ let message = "Hello!";
let phrase = message;
```

As a result we have two independent variables, each one is storing the string `"Hello!"`.
As a result we have two independent variables, each one storing the string `"Hello!"`.

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

Quite an obvious result, right?

Objects are not like that.

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

Let's look at an example of such variable:
Let's look at an example of such a variable:

```js
let user = {
Expand All @@ -37,13 +37,13 @@ And here's how it's actually stored in memory:

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.

We may think of an object variable, such as `user`, as of a sheet of paper with the address.
We may think of an object variable, such as `user`, as like a sheet of paper with the address of the object on it.

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.
When we perform actions with the object, e.g. take a property `user.name`, the JavaScript engine looks at what's at that address and performs the operation on the actual object.

Now here's why it's important.

**When an object variable is copied -- the reference is copied, the object is not duplicated.**
**When an object variable is copied, the reference is copied, but the object itself is not duplicated.**

For instance:

Expand All @@ -53,13 +53,13 @@ let user = { name: "John" };
let admin = user; // copy the reference
```

Now we have two variables, each one with the reference to the same object:
Now we have two variables, each storing a reference to the same object:

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

As you can see, there's still one object, now with two variables that reference it.
As you can see, there's still one object, but now with two variables that reference it.

We can use any variable to access the object and modify its contents:
We can use either variable to access the object and modify its contents:

```js run
let user = { name: 'John' };
Expand All @@ -73,8 +73,7 @@ admin.name = 'Pete'; // changed by the "admin" reference
alert(*!*user.name*/!*); // 'Pete', changes are seen from the "user" reference
```


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.
It's as if we had a cabinet with two keys and used one of them (`admin`) to get into it and make changes. Then, if we later use another key (`user`), we are still opening the same cabinet and can access the changed contents.

## Comparison by reference

Expand All @@ -99,15 +98,15 @@ let b = {}; // two independent objects
alert( a == b ); // false
```

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.
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.

## Cloning and merging, Object.assign

So, copying an object variable creates one more reference to the same object.

But what if we need to duplicate an object? Create an independent copy, a clone?

That's also doable, but a little bit more difficult, because there's no built-in method for that in JavaScript. Actually, that's rarely needed. Copying by reference is good most of the time.
That's also doable, but a little bit more difficult, because there's no built-in method for that in JavaScript. But there is rarely a need -- copying by reference is good most of the time.

But if we really want that, then we need to create a new object and replicate the structure of the existing one by iterating over its properties and copying them on the primitive level.

Expand Down Expand Up @@ -226,13 +225,37 @@ user.sizes.width++; // change a property from one place
alert(clone.sizes.width); // 51, see the result from the other one
```

To fix that, we should use the cloning loop that examines each value of `user[key]` and, if it's an object, then replicate its structure as well. That is called a "deep cloning".
To fix that, we should use a cloning loop that examines each value of `user[key]` and, if it's an object, then replicate its structure as well. That is called a "deep cloning".

We can use recursion to implement it. Or, to not reinvent the wheel, take an existing implementation, for instance [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep) from the JavaScript library [lodash](https://lodash.com).

````smart header="Const objects can be modified"
An important side effect of storing objects as references is that an object declared as `const` *can* be modified.

For instance:

```js run
const user = {
name: "John"
};

*!*
user.name = "Pete"; // (*)
*/!*

alert(user.name); // Pete
```

It might seem that the line `(*)` would cause an error, but it does not. The value of `user` is constant, it must always reference the same object, but properties of that object are free to change.

In other words, the `const user` gives an error only if we try to set `user=...` as a whole.

We can use recursion to implement it. Or, not to reinvent the wheel, take an existing implementation, for instance [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep) from the JavaScript library [lodash](https://lodash.com).
That said, if we really need to make constant object properties, it's also possible, but using totally different methods. We'll mention that in the chapter <info:property-descriptors>.
````

## Summary

Objects are assigned and copied by reference. In other words, a variable stores not the "object value", but a "reference" (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object.
Objects are assigned and copied by reference. In other words, a variable stores not the "object value", but a "reference" (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object itself.

All operations via copied references (like adding/removing properties) are performed on the same single object.

Expand Down
8 changes: 4 additions & 4 deletions 1-js/04-object-basics/07-optional-chaining/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The optional chaining `?.` is a safe way to access nested object properties, eve

If you've just started to read the tutorial and learn JavaScript, maybe the problem hasn't touched you yet, but it's quite common.

As an example, let's say we have `user` objects that hold the information about our users.
As an example, let's say we have `user` objects that hold the information about our users.

Most of our users have addresses in `user.address` property, with the street `user.address.street`, but some did not provide them.

Expand All @@ -21,7 +21,7 @@ let user = {}; // a user without "address" property
alert(user.address.street); // Error!
```

That's the expected result. JavaScript works like this. As `user.address` is `undefined`, an attempt to get `user.address.street` fails with an error.
That's the expected result. JavaScript works like this. As `user.address` is `undefined`, an attempt to get `user.address.street` fails with an error.

In many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street").

Expand Down Expand Up @@ -56,7 +56,7 @@ let user = {}; // user has no address
alert(user.address ? user.address.street ? user.address.street.name : null : null);
```

That's just awful, one may even have problems understanding such code.
That's just awful, one may even have problems understanding such code.

Don't even care to, as there's a better way to write it, using the `&&` operator:

Expand All @@ -80,7 +80,7 @@ The optional chaining `?.` stops the evaluation if the part before `?.` is `unde

In other words, `value?.prop`:
- is the same as `value.prop` if `value` exists,
- otherwise (when `value` is `undefined/null`) it returns that `value`.
- otherwise (when `value` is `undefined/null`) it returns `undefined`.

Here's the safe way to access `user.address.street` using `?.`:

Expand Down
2 changes: 1 addition & 1 deletion 1-js/05-data-types/03-string/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ alert( str.indexOf('widget') ); // -1, not found, the search is case-sensitive
alert( str.indexOf("id") ); // 1, "id" is found at the position 1 (..idget with id)
```

The optional second parameter allows us to search starting from the given position.
The optional second parameter allows us to start searching from a given position.

For instance, the first occurrence of `"id"` is at position `1`. To look for the next occurrence, let's start the search from position `2`:

Expand Down
4 changes: 2 additions & 2 deletions 1-js/05-data-types/05-array-methods/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ These methods are the most used ones, they cover 99% of use cases. But there are
- [arr.some(fn)](mdn:js/Array/some)/[arr.every(fn)](mdn:js/Array/every) check the array.

The function `fn` is called on each element of the array similar to `map`. If any/all results are `true`, returns `true`, otherwise `false`.
These methods behave sort of like `||` and `&&` operators: if `fn` returns a truthy value, `arr.some()` immediately returns `true` and stops iterating over the rest items; if `fn` returns a falsy value, `arr.every()` immediately returns `false` and stops iterating over the rest items as well.

These methods behave sort of like `||` and `&&` operators: if `fn` returns a truthy value, `arr.some()` immediately returns `true` and stops iterating over the rest of items; if `fn` returns a falsy value, `arr.every()` immediately returns `false` and stops iterating over the rest of items as well.

We can use `every` to compare arrays:
```js run
Expand Down
Loading