Skip to content

Commit dd3838b

Browse files
authored
Merge pull request #74 from javascript-tutorial/sync-d35baee3
Sync with upstream @ d35baee
2 parents 31143ba + fb4993e commit dd3838b

8 files changed

Lines changed: 63 additions & 32 deletions

File tree

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ let user = 'John'
8383

8484
تقنيا, كل هذه الطرق تؤدي لنفس الشئ. لذلك, انها مسألة ذوق وجمال شخصي.
8585

86-
8786
````smart header="`var` بدلا من `let`"
88-
في الاصدارات الاقدم, قد تجد ايضا كلمة اخري: `var` بدلا من `let`
87+
في الاصدارات الاقدم, قد تجد ايضا كلمة اخري: `var` بدلا من `let`:
8988

9089
```js
9190
*!*var*/!* message = 'Hello';
@@ -136,6 +135,20 @@ alert(hello); // Hello world!
136135
alert(message); // Hello world!
137136
```
138137
138+
````warn header="Declaring twice triggers an error"
139+
A variable should be declared only once.
140+
141+
A repeated declaration of the same variable is an error:
142+
143+
```js run
144+
let message = "This";
145+
146+
// repeated 'let' leads to an error
147+
let message = "That"; // SyntaxError: 'message' has already been declared
148+
```
149+
So, we should declare a variable once and then refer to it without `let`.
150+
````
151+
139152
```smart header="Functional languages"
140153
من المثير للاهتمام ملاحظة وجود [وظيفي](https://en.wikipedia.org/wiki/Functional_programming) لغات برمجه, مثل [Scala](http://www.scala-lang.org/) او [Erlang](http://www.erlang.org/) تمنع تغيير قيم المتغير.
141154
@@ -191,7 +204,8 @@ let имя = '...';
191204
let 我 = '...';
192205
```
193206
194-
تقنياً, لا يوجد خطأ هنا, مثل هذه الاسماء مسموح بها, ولكن هناك تقاليد عالميه لأستخدام اللغه الانجليزيه في أسماء المتغيرات. حتي لو كنا نكتب نصاً صغيراً, قد يكون لها حياة طويله في المستقبل. الناس من مختلف البلاد ربما يحتاجوا لقرأءتها في بنفس الكتابة.
207+
تقنياً, لا يوجد خطأ هنا, مثل هذه الاسماء مسموح بها, ولكن هناك تقاليد عالميه لأستخدام اللغه الانجليزيه في أسماء المتغيرات. حتي لو كنا نكتب نصاً صغيراً, قد يكون لها حياة طويله في المستقبل. الناس من مختلف البلاد ربما يحتاجوا لقرأءتها لبعض الوقت.
208+
195209
````
196210

197211
````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: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,18 @@ In the very first chapter about [variables](info:variables), we mentioned three
1313
2. `const`
1414
3. `var`
1515

16-
`let` and `const` behave exactly the same way in terms of Lexical Environments.
17-
18-
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.
19-
20-
If you don't plan on meeting such scripts you may even skip this chapter or postpone it, but then there's a chance that it bites you later.
21-
22-
From the first sight, `var` behaves similar to `let`. That is, declares a variable:
16+
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:
2317

2418
```js run
25-
function sayHi() {
26-
var phrase = "Hello"; // local variable, "var" instead of "let"
27-
28-
alert(phrase); // Hello
29-
}
19+
var message = "Hi";
20+
alert(message); // Hi
21+
```
3022

31-
sayHi();
23+
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.
3224

33-
alert(phrase); // Error, phrase is not defined
34-
```
25+
If you don't plan on meeting such scripts you may even skip this chapter or postpone it.
3526

36-
...But here are the differences.
27+
On the other hand, it's important to understand differences when migrating old scripts from `var` to `let`, to avoid odd errors.
3728

3829
## "var" has no block scope
3930

@@ -94,7 +85,27 @@ alert(phrase); // Error: phrase is not defined (Check the Developer Console)
9485

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

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

99110
`var` declarations are processed when the function starts (or script starts for globals).
100111

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function isHidden(elem) {
150150

151151
تتضمن عرض المحتوى مع الحشو ، لكن بدون شريط التمرير:
152152

153-
! [] (metric-client-width-height.svg)
153+
![](metric-client-width-height.svg)
154154

155155
في الصورة أعلاه ، لنفكر أولاً في "clientHeight".
156156

@@ -169,7 +169,7 @@ function isHidden(elem) {
169169

170170
هذه الخصائص مثل `clientWidth / clientHeight` ، ولكنها تشمل أيضًا الأجزاء التي تم تمريرها (المخفية):
171171

172-
! [] (metric-roll-width-height.svg)
172+
![](metric-roll-width-height.svg)
173173

174174
في الصورة أعلاه:
175175

@@ -199,22 +199,22 @@ element.style.height = `${element.scrollHeight}px`;
199199

200200
في الصورة أدناه ، يمكننا رؤية "التمرير" و "التمرير العلوي" للكتلة ذات التمرير العمودي.
201201

202-
! [] (metric-تمرير-top.svg)
202+
![](metric-scroll-top.svg)
203203

204204
وبعبارة أخرى ، فإن "rollTop" هو "مقدار التمرير".
205205

206-
`` `` smart header = "يمكن تعديل" التمرير لليسار / التمرير العلوي "
206+
````smart header = "يمكن تعديل" التمرير لليسار / التمرير العلوي "
207207
معظم الخصائص الهندسية هنا للقراءة فقط ، ولكن يمكن تغيير `التمرير لليسار / التمرير العلوي` ، وسوف يقوم المتصفح بتمرير العنصر.
208208
209-
`` عبر الإنترنت
209+
```online
210210
إذا قمت بالنقر فوق العنصر أدناه ، فسيتم تنفيذ الرمز `elem.scrollTop + = 10`. هذا يجعل محتوى العنصر بالتمرير `10px` للأسفل.
211211
212212
213213
<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>
214214
```
215215
216-
يؤدي تعيين "التمرير" إلى "0" أو "إنفينيتي" إلى جعل العنصر ينتقل إلى الأعلى / الأسفل على التوالي.
217-
`` ``
216+
يؤدي تعيين "scrollTop" إلى "0" أو "إنفينيتي" إلى جعل العنصر ينتقل إلى الأعلى/الأسفل على التوالي.
217+
````
218218

219219
## لا تأخذ العرض / الارتفاع من CSS
220220

@@ -275,4 +275,4 @@ alert( getComputedStyle(elem).width ); // show CSS width for elem
275275
- "التمرير / التمرير" - عرض / ارتفاع المحتوى ، مثل "clientWidth / clientHeight" ، ولكن يشمل أيضًا الجزء غير المرئي من العنصر.
276276
- `التمرير لليسار / التمرير العلوي` - عرض / ارتفاع الجزء العلوي الذي تم تمريره للخارج من العنصر ، بدءًا من الزاوية العلوية اليسرى.
277277

278-
جميع الخصائص للقراءة فقط باستثناء `التمرير الأيسر / التمرير العلوي` والتي تجعل المتصفح يقوم بتمرير العنصر إذا تم تغييره.
278+
جميع الخصائص للقراءة فقط باستثناء `التمرير الأيسر / التمرير العلوي` والتي تجعل المتصفح يقوم بتمرير العنصر إذا تم تغييره.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ The code sets click handlers on *every* element in the document to see which one
181181
If you click on `<p>`, then the sequence is:
182182

183183
1. `HTML` -> `BODY` -> `FORM` -> `DIV` (capturing phase, the first listener):
184-
2. `P` (target phrase, triggers two times, as we've set two listeners: capturing and bubbling)
184+
2. `P` (target phase, triggers two times, as we've set two listeners: capturing and bubbling)
185185
3. `DIV` -> `FORM` -> `BODY` -> `HTML` (bubbling phase, the second listener).
186186

187187
There's a property `event.eventPhase` that tells us the number of the phase on which the event was caught. But it's rarely used, because we usually know it in the handler.

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)