Skip to content

Commit 17f2f44

Browse files
committed
merging all conflicts
2 parents 9ef4447 + d35baee commit 17f2f44

8 files changed

Lines changed: 78 additions & 13 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ let user = 'John'
7979

8080
از لحاظ فنی همه این حالات کار خواهند کرد و انتخاب آن‌ها به سلایق و زیبایی شناسی شخصی مربوط است.
8181

82+
<<<<<<< HEAD
8283

8384
````smart header="`var` بجای `let`"
8485
در اسکریپت‌های قدیمی ممکن است بجای کلیدواژه `let` با کلیدواژه `var` برخورد کنید :
86+
=======
87+
````smart header="`var` instead of `let`"
88+
In older scripts, you may also find another keyword: `var` instead of `let`:
89+
>>>>>>> d35baee32dcce127a69325c274799bb81db1afd8
8590
8691
```js
8792
*!*var*/!* message = 'Hello';
@@ -132,8 +137,27 @@ alert(hello); // Hello world!
132137
alert(message); // Hello world!
133138
```
134139
140+
<<<<<<< HEAD
135141
```smart header="زبان‌های Functional"
136142
جالب است بدانید زبان‌های [functional](https://en.wikipedia.org/wiki/Functional_programming) مانند [Scala](http://www.scala-lang.org/) یا [Erlang](http://www.erlang.org/) تغییر مقدار متغیر را ممنوع کرده‌اند.
143+
=======
144+
````warn header="Declaring twice triggers an error"
145+
A variable should be declared only once.
146+
147+
A repeated declaration of the same variable is an error:
148+
149+
```js run
150+
let message = "This";
151+
152+
// repeated 'let' leads to an error
153+
let message = "That"; // SyntaxError: 'message' has already been declared
154+
```
155+
So, we should declare a variable once and then refer to it without `let`.
156+
````
157+
158+
```smart header="Functional languages"
159+
It's interesting to note that there exist [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/) that forbid changing variable values.
160+
>>>>>>> d35baee32dcce127a69325c274799bb81db1afd8
137161
138162
در این نوع زبان‌ها وقتی مقداری را در جعبه قرار می‌دهیم تا ابد آنجا می‌ماند و اگر بخواهیم مقداری دیگر را ذخیره کنیم، ما را مجبور می‌کنند تا جعبه‌ای جدید بسازیم.
139163
@@ -188,7 +212,11 @@ let имя = '...';
188212
let 我 = '...';
189213
```
190214
215+
<<<<<<< HEAD
191216
از نظر فنی اینها درست کار می‌کنند ولی بر اساس یک رسم بین‌المللی برای نام متغیرها از زبان انگلیسی استفاده می‌شود. حتی اگر اسکریپتی کوچک می‌نویسیم، ممکن است تا مدت طولانی‌ای مورد استفاده و توسعه قرار بگیرد و اشخاصی از سایر کشورها ممکن است نیاز باشد روزی آن اسکریپت را بخوانند.
217+
=======
218+
Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it some time.
219+
>>>>>>> d35baee32dcce127a69325c274799bb81db1afd8
192220
````
193221

194222
````warn header="نام‌های رِزِرو شده"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ Of course, a team can always write their own style guide, but usually there's no
285285
286286
Some popular choices:
287287
288-
- [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml)
288+
- [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
289289
- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
290290
- [Idiomatic.JS](https://github.com/rwaldron/idiomatic.js)
291291
- [StandardJS](https://standardjs.com/)

1-js/03-code-quality/05-testing-mocha/beforeafter.view/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
describe("test", function() {
2+
3+
// Mocha usually waits for the tests for 2 seconds before considering them wrong
4+
5+
this.timeout(200000); // With this code we increase this - in this case to 200,000 milliseconds
26

7+
// This is because of the "alert" function, because if you delay pressing the "OK" button the tests will not pass!
8+
39
before(() => alert("Testing started – before all tests"));
410
after(() => alert("Testing finished – after all tests"));
511

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ So, for the task of turning something into an array, `Array.from` tends to be mo
227227
228228
## Get a new copy of an array/object
229229
230-
Remember when we talked about `Object.assign()` [in the past](https://javascript.info/object#cloning-and-merging-object-assign)?
230+
Remember when we talked about `Object.assign()` [in the past](info:object-copy#cloning-and-merging-object-assign)?
231231
232232
It is possible to do the same thing with the spread syntax.
233233

1-js/06-advanced-functions/04-var/article.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,28 @@ In the very first chapter about [variables](info:variables), we mentioned three
1313
2. `const`
1414
3. `var`
1515

16+
<<<<<<< HEAD
1617
`let` and `const` behave exactly the same way in terms of Lexical Environments.
1718

1819
But `var` is a very different beast, that originates from very old times. It's generally not used in modern scripts, but still lurks in the old ones.
1920

2021
If you don't plan meeting such scripts you may even skip this chapter or postpone it, but then there's a chance that it bites you later.
2122

2223
From the first sight, `var` behaves similar to `let`. That is, declares a variable:
24+
=======
25+
The `var` declaration is similar to `let`. Most of the time we can replace `let` by `var` or vice-versa and expect things to work:
26+
>>>>>>> d35baee32dcce127a69325c274799bb81db1afd8
2327
2428
```js run
25-
function sayHi() {
26-
var phrase = "Hello"; // local variable, "var" instead of "let"
29+
var message = "Hi";
30+
alert(message); // Hi
31+
```
2732

28-
alert(phrase); // Hello
29-
}
33+
But internally `var` is a very different beast, that originates from very old times. It's generally not used in modern scripts, but still lurks in the old ones.
3034

31-
sayHi();
35+
If you don't plan on meeting such scripts you may even skip this chapter or postpone it.
3236

33-
alert(phrase); // Error, phrase is not defined
34-
```
35-
36-
...But here are the differences.
37+
On the other hand, it's important to understand differences when migrating old scripts from `var` to `let`, to avoid odd errors.
3738

3839
## "var" has no block scope
3940

@@ -82,7 +83,31 @@ alert(phrase); // Error: phrase is not defined
8283

8384
As we can see, `var` pierces through `if`, `for` or other code blocks. That's because a long time ago in JavaScript blocks had no Lexical Environments. And `var` is a remnant of that.
8485

86+
<<<<<<< HEAD
8587
## "var" are processed at the function start
88+
=======
89+
## "var" tolerates redeclarations
90+
91+
If we declare the same variable with `let` twice in the same scope, that's an error:
92+
93+
```js run
94+
let user;
95+
let user; // SyntaxError: 'user' has already been declared
96+
```
97+
98+
With `var`, we can redeclare a variable any number of times. If we use `var` with an already-declared variable, it's just ignored:
99+
100+
```js run
101+
var user = "Pete";
102+
103+
var user = "John"; // this "var" does nothing (already declared)
104+
// ...it doesn't trigger an error
105+
106+
alert(user); // John
107+
```
108+
109+
## "var" variables can be declared below their use
110+
>>>>>>> d35baee32dcce127a69325c274799bb81db1afd8
86111
87112
`var` declarations are processed when the function starts (or script starts for globals).
88113

2-ui/1-document/09-size-and-scroll/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ If you click the element below, the code `elem.scrollTop += 10` executes. That m
211211
<div onclick="this.scrollTop+=10" style="cursor:pointer;border:1px solid black;width:100px;height:80px;overflow:auto">Click<br>Me<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9</div>
212212
```
213213

214-
Setting `scrollTop` to `0` or `Infinity` will make the element scroll to the very top/bottom respectively.
214+
Setting `scrollTop` to `0` or a big value, such as `1e9` will make the element scroll to the very top/bottom respectively.
215215
````
216216
217217
## Don't take width/height from CSS

2-ui/2-events/02-bubbling-and-capturing/article.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,14 @@ The code sets click handlers on *every* element in the document to see which one
175175

176176
If you click on `<p>`, then the sequence is:
177177

178+
<<<<<<< HEAD
178179
1. `HTML` -> `BODY` -> `FORM` -> `DIV` -> `P` (capturing phase, the first listener), and then:
179180
2. `P` -> `DIV` -> `FORM` -> `BODY` -> `HTML` (bubbling phase, the second listener).
181+
=======
182+
1. `HTML` -> `BODY` -> `FORM` -> `DIV` (capturing phase, the first listener):
183+
2. `P` (target phase, triggers two times, as we've set two listeners: capturing and bubbling)
184+
3. `DIV` -> `FORM` -> `BODY` -> `HTML` (bubbling phase, the second listener).
185+
>>>>>>> d35baee32dcce127a69325c274799bb81db1afd8
180186
181187
Please note that `P` shows up two times: at the end of capturing and at the start of bubbling.
182188

2-ui/3-event-details/4-mouse-drag-and-drop/ball2.view/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
<script>
16-
ball.onmousedown = function(event) {s
16+
ball.onmousedown = function(event) {
1717
ball.style.position = 'absolute';
1818
ball.style.zIndex = 1000;
1919
document.body.appendChild(ball);

0 commit comments

Comments
 (0)