Skip to content

Commit 18e0e2b

Browse files
committed
merging all conflicts
2 parents 4edfab1 + 69e4450 commit 18e0e2b

21 files changed

Lines changed: 180 additions & 42 deletions

File tree

1-js/02-first-steps/03-strict-mode/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For example:
1919
...
2020
```
2121

22-
Quite soon we're going to learn functions (a way to group commands) soon, so let's note in advance that `"use strict"` can be put at the beginning of a function. Doing that enables strict mode in that function only. But usually people use it for the whole script.
22+
Quite soon we're going to learn functions (a way to group commands), so let's note in advance that `"use strict"` can be put at the beginning of a function. Doing that enables strict mode in that function only. But usually people use it for the whole script.
2323

2424
````warn header="Ensure that \"use strict\" is at the top"
2525
Please make sure that `"use strict"` is at the top of your scripts, otherwise strict mode may not be enabled.

1-js/02-first-steps/05-types/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const bigInt = 1234567890123456789012345678901234567890n;
8282
As `BigInt` numbers are rarely needed, we don't cover them here, but devoted them a separate chapter <info:bigint>. Read it when you need such big numbers.
8383

8484
```smart header="Compatability issues"
85-
Right now `BigInt` is supported in Firefox and Chrome, but not in Safari/IE/Edge.
85+
Right now `BigInt` is supported in Firefox/Chrome/Edge, but not in Safari/IE.
8686
```
8787

8888
## String
@@ -257,7 +257,7 @@ There are 8 basic data types in JavaScript.
257257

258258
- `number` for numbers of any kind: integer or floating-point, integers are limited by ±2<sup>53</sup>.
259259
- `bigint` is for integer numbers of arbitrary length.
260-
- `string` for strings. A string may have one or more characters, there's no separate single-character type.
260+
- `string` for strings. A string may have zero or more characters, there's no separate single-character type.
261261
- `boolean` for `true`/`false`.
262262
- `null` for unknown values -- a standalone type that has a single value `null`.
263263
- `undefined` for unassigned values -- a standalone type that has a single value `undefined`.

1-js/02-first-steps/09-comparison/article.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
: وفي لغة الجافسكريبت تكتب كما يلي
66

7+
<<<<<<< HEAD
78
- أكبر من وأصغر من: <code>a &gt; b</code>, <code>a &lt; b</code>.
89
- أكبر : <code>a &gt;= b</code>, <code>a &lt;= b</code>.
910
- يساوي: `a == b` ، يرجى ملاحظة أن علامة المساواة المزدوجة` = `تعني اختبار المساواة ، في حين أن كلمة واحدة` a = b` تعني تعيين أو مساواة .
1011
- لا تساوي. في الرياضيات ، يكون الترميز في JavaScript مكتوب مثل a !=b
12+
=======
13+
- Greater/less than: <code>a &gt; b</code>, <code>a &lt; b</code>.
14+
- Greater/less than or equals: <code>a &gt;= b</code>, <code>a &lt;= b</code>.
15+
- Equals: `a == b`, please note the double equality sign `=` means the equality test, while a single one `a = b` means an assignment.
16+
- Not equals. In maths the notation is <code>&ne;</code>, but in JavaScript it's written as <code>a != b</code>.
17+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
1118
1219
في هذه المقالة سنتعلم المزيد عن الأنواع المختلفة من المقارنات ، وكيف تجعلها JavaScript ، بما في ذلك الخصائص المهمة.
1320

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,28 @@ alert( undefined || null || 0 ); // 0 (الكل falsy, ترجع آخر قيمة)
125125

126126
أهمية هذه الميزة تصبح ملحوظة إذا كانت القيمة الممررة عبارة عن عملية لها آثار جانبية مثل تخصيص قيمة متغير أو استدعاء دالة
127127

128+
<<<<<<< HEAD
128129
في هذا المثال سيتم طباعة الرسالة الأولى ولن يتم طباعة الثانية:
129130

130131
```js run no-beautify
131132
*!*false*/!* || alert("printed");
132133
*!*true*/!* || alert("not printed");
134+
=======
135+
In the example below, only the second message is printed:
136+
137+
```js run no-beautify
138+
*!*true*/!* || alert("not printed");
139+
*!*false*/!* || alert("printed");
140+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
133141
```
134142

135143
في السطر الثاني يتوقف المعامل OR `||` مباشرة عند الوصول إلى `true` لذلك فإن `alert` لا ينفذ.
136144

145+
<<<<<<< HEAD
137146
أحيانًا يستخدم الناس هذه الخاصية لتنفيذ أوامر فقط إذا كان الجزء الأيسر truthy.
147+
=======
148+
Sometimes, people use this feature to execute commands only if the condition on the left part is falsy.
149+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
138150

139151
## && (AND)
140152

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,58 @@ x = (a !== null && a !== undefined) ? a : b;
1616

1717
هذا مثال أطول.
1818

19+
<<<<<<< HEAD
1920
لنفترض أن لدينا `firstName`, `lastName` أو `nickName` وجميعهم اختياريين.
2021

2122
لنختار القيمة المعرفة ونعرضها (أو نعرض "Anonymous" إذا لم يحدد أي شئ):
23+
=======
24+
Imagine, we have a user, and there are variables `firstName`, `lastName` or `nickName` for their first name, last name and the nick name. All of them may be undefined, if the user decided not to enter any value.
25+
26+
We'd like to display the user name: one of these three variables, or show "Anonymous" if nothing is set.
27+
28+
Let's use the `??` operator to select the first defined one:
29+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
2230
2331
```js run
2432
let firstName = null;
2533
let lastName = null;
2634
let nickName = "Supercoder";
2735

28-
// show the first not-null/undefined variable
36+
// show the first not-null/undefined value
37+
*!*
2938
alert(firstName ?? lastName ?? nickName ?? "Anonymous"); // Supercoder
39+
*/!*
3040
```
3141
3242
## المقارنة مع ||
3343
44+
<<<<<<< HEAD
3445
هذا مشابه جدًا للمعامل `||`. في الحقيقة يمكننا استبدال `??` ب `||` في المثال السابق وسنحصل على نفس النتيجة.
46+
=======
47+
The OR `||` operator can be used in the same way as `??`. Actually, we can replace `??` with `||` in the code above and get the same result, as it was described in the [previous chapter](info:logical-operators#or-finds-the-first-truthy-value).
48+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
3549
3650
الفرق الجوهري بينهما أن:
3751
- `||` يرجع أول قيمة *truthy*.
3852
- `??` يرجع أول قيمة *defined*.
3953
4054
هذا مهم جدًا عندما نريد معاملة `null/undefined` بطريقة مختلفة عن `0`.
4155
56+
<<<<<<< HEAD
4257
مثلًا:
58+
=======
59+
For example, consider this:
60+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
4361
4462
```js
4563
height = height ?? 100;
4664
```
4765
66+
<<<<<<< HEAD
4867
هذا يجعل `height` يساوي `100` إذا لم يعرف. ولكن إذا كان `height` يساوي `0` سيبقى كما هو.
68+
=======
69+
This sets `height` to `100` if it's not defined.
70+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
4971
5072
لنقارنه مع `||`:
5173
@@ -56,17 +78,31 @@ alert(height || 100); // 100
5678
alert(height ?? 100); // 0
5779
```
5880
81+
<<<<<<< HEAD
5982
هنا `height || 100` تعامل الصفر مثل `null`, `undefined` أو أي قيمة falsy أخرىوهذا قد لا يكون صحيح أحيانًا.
6083
6184
ولكن `height ?? 100` ترجع `100` إذا كان فقط `height` يساوي تمامًا `null` أو `undefined`.
85+
=======
86+
Here, `height || 100` treats zero height as unset, same as `null`, `undefined` or any other falsy value. So zero becames `100`.
87+
88+
The `height ?? 100` returns `100` only if `height` is exactly `null` or `undefined`. So zero remains "as is".
89+
90+
Which behavior is better depends on a particular use case. When zero height is a valid value, that we shouldn't touch, then `??` is preferrable.
91+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
6292
6393
## الأولوية
6494
6595
أولوية المعامل `??` هي قليلة: `7` وتساوي [MDN جدول](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table).
6696
97+
<<<<<<< HEAD
6798
هذا أقل من معظم المعاملات وأكبر بقليل من `=` و `?`.
6899
69100
لذلك إذا أردنا استخدام `??` في تعبيرات معقدة نقوم بإضافة أقواس:
101+
=======
102+
So `??` is evaluated after most other operations, but before `=` and `?`.
103+
104+
If we need to choose a value with `??` in a complex expression, then consider adding parentheses:
105+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
70106
71107
```js run
72108
let height = null;
@@ -78,6 +114,7 @@ let area = (height ?? 100) * (width ?? 50);
78114
alert(area); // 5000
79115
```
80116
117+
<<<<<<< HEAD
81118
إذا لم نستخدم الأقواس فإن `*` له أولوية أعلى وسينفذ أولًا كأننا كتبنا:
82119
83120
```js
@@ -86,19 +123,45 @@ let area = height ?? (100 * width) ?? 50;
86123
```
87124
88125
هناك أيضًا قيود لغوية. لأسباب أمنية لا يمكن استخدام `??` مع `&&` أو `||`.
126+
=======
127+
Otherwise, if we omit parentheses, `*` has the higher precedence than `??` and would run first.
128+
129+
That would work be the same as:
130+
131+
```js
132+
// probably not correct
133+
let area = height ?? (100 * width) ?? 50;
134+
```
135+
136+
There's also a related language-level limitation.
137+
138+
**Due to safety reasons, it's forbidden to use `??` together with `&&` and `||` operators.**
139+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
89140
90141
هذا سينتج خطأ لغوي:
91142
92143
```js run
93144
let x = 1 && 2 ?? 3; // Syntax error
94145
```
95146
147+
<<<<<<< HEAD
96148
هذا القيد قد لا يبدو منطقيًا ولكن لبعض الأسباب تم إضافته للغة.
97149
98150
استخدم الأقواس لتجنب الخطأ:
99151
100152
```js run
101153
let x = (1 && 2) ?? 3; // تعمل دون مشاكل
154+
=======
155+
The limitation is surely debatable, but it was added to the language specification with the purpose to avoid programming mistakes, as people start to switch to `??` from `||`.
156+
157+
Use explicit parentheses to work around it:
158+
159+
```js run
160+
*!*
161+
let x = (1 && 2) ?? 3; // Works
162+
*/!*
163+
164+
>>>>>>> 69e44506c3e9dac74c282be37b55ba7ff122ae74
102165
alert(x); // 2
103166
```
104167

1-js/04-object-basics/07-optional-chaining/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ user2.admin?.();
124124
125125
Here, in both lines we first use the dot `.` to get `admin` property, because the user object must exist, so it's safe read from it.
126126
127-
Then `?.()` checks the left part: if the user exists, then it runs (for `user1`). Otherwise (for `user2`) the evaluation stops without errors.
127+
Then `?.()` checks the left part: if the admin function exists, then it runs (for `user1`). Otherwise (for `user2`) the evaluation stops without errors.
128128
129129
The `?.[]` syntax also works, if we'd like to use brackets `[]` to access properties instead of dot `.`. Similar to previous cases, it allows to safely read a property from an object that may not exist.
130130

1-js/05-data-types/05-array-methods/12-reduce-object/_js.view/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ describe("groupById", function() {
88
];
99

1010
assert.deepEqual(groupById(users), {
11-
john: {id: 'john', name: "John Smith", age: 20}
11+
john: {id: 'john', name: "John Smith", age: 20},
1212
ann: {id: 'ann', name: "Ann Smith", age: 24},
1313
pete: {id: 'pete', name: "Pete Peterson", age: 31},
1414
});
1515
});
1616

1717
it("works with an empty array", function() {
18+
users = [];
1819
assert.deepEqual(groupById(users), {});
1920
});
2021
});

1-js/05-data-types/05-array-methods/12-reduce-object/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let usersById = groupById(users);
2323
// after the call we should have:
2424
2525
usersById = {
26-
john: {id: 'john', name: "John Smith", age: 20}
26+
john: {id: 'john', name: "John Smith", age: 20},
2727
ann: {id: 'ann', name: "Ann Smith", age: 24},
2828
pete: {id: 'pete', name: "Pete Peterson", age: 31},
2929
}

1-js/05-data-types/07-map-set/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ let prices = Object.fromEntries([
198198
alert(prices.orange); // 2
199199
```
200200
201-
We can use `Object.fromEntries` to get an plain object from `Map`.
201+
We can use `Object.fromEntries` to get a plain object from `Map`.
202202
203203
E.g. we store the data in a `Map`, but we need to pass it to a 3rd-party code that expects a plain object.
204204
@@ -220,7 +220,7 @@ let obj = Object.fromEntries(map.entries()); // make a plain object (*)
220220
alert(obj.orange); // 2
221221
```
222222
223-
A call to `map.entries()` returns an array of key/value pairs, exactly in the right format for `Object.fromEntries`.
223+
A call to `map.entries()` returns an iterable of key/value pairs, exactly in the right format for `Object.fromEntries`.
224224
225225
We could also make line `(*)` shorter:
226226
```js

1-js/05-data-types/11-date/6-get-seconds-today/solution.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ function getSecondsToday() {
2323
let d = new Date();
2424
return d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds();
2525
}
26+
27+
alert( getSecondsToday() );
2628
```

0 commit comments

Comments
 (0)