Skip to content

Commit 4aa00c2

Browse files
authored
Merge pull request #63 from Abdulrahmanh95/javascript-specials
JavaScript specials
2 parents c2f025e + 7fe0b4f commit 4aa00c2

File tree

1 file changed

+98
-97
lines changed
  • 1-js/02-first-steps/18-javascript-specials

1 file changed

+98
-97
lines changed
Lines changed: 98 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,120 @@
1-
# JavaScript specials
1+
# خاصّيات جافاسكريبت
22

3-
This chapter briefly recaps the features of JavaScript that we've learned by now, paying special attention to subtle moments.
3+
يلخص هذا الفصل بإيجاز ميزات جافاسكريبت التي تعلمناها حتى الآن، مع التركيز بشكل دقيق على مواضيع معيّنة.
44

5-
## Code structure
5+
## هيكل الكود البرمجي
66

7-
Statements are delimited with a semicolon:
7+
يتم الفصل بين التعابير بفاصلة منقوطة:
88

99
```js run no-beautify
1010
alert('Hello'); alert('World');
1111
```
1212

13-
Usually, a line-break is also treated as a delimiter, so that would also work:
13+
كما يمكن اعتبار السطر الجديد كفاصل أيضاً بين التعابير:
1414

1515
```js run no-beautify
1616
alert('Hello')
1717
alert('World')
1818
```
1919

20-
That's called "automatic semicolon insertion". Sometimes it doesn't work, for instance:
20+
وهذا ما ندعوه بـِ "الإدراج التلقائي للفاصلة المنقوطة"، ولكنه لا يعمل بشكل صحيح في بعض الأحيان، فعلى سبيل المثال:
2121

2222
```js run
2323
alert("There will be an error after this message")
2424

2525
[1, 2].forEach(alert)
2626
```
2727

28-
Most codestyle guides agree that we should put a semicolon after each statement.
28+
وهنا يجب التنويه أن معظم الأدلة والبرامج التعليمية تشير إلى أنه من الأفضل أن نضع الفواصل المنقوطة عند نهاية التعابير.
2929

30-
Semicolons are not required after code blocks `{...}` and syntax constructs with them like loops:
30+
إلا أنه ليس مطلوبٌ وضع هذه الفواصل المنقوطة عند نهاية أقواس الكتل البرمجية `{...}` والتعليمات الخاصة كالحلقات على سبيل المثال:
3131

3232
```js
3333
function f() {
34-
// no semicolon needed after function declaration
34+
// ليس من المطلوب وضع الفاصلة المنقوطة بعد تعريف التابع
3535
}
3636

3737
for(;;) {
38-
// no semicolon needed after the loop
38+
// ليس من المطلوب وضع الفاصلة المنقوطة بعد الحلقة التكرارية
3939
}
4040
```
4141

42-
...But even if we can put an "extra" semicolon somewhere, that's not an error. It will be ignored.
42+
ولكن حتى لو قمنا بوضع فاصلة منقوطة إضافية في مكان ما، فهذا ليس بخطأ، حيث سيتمّ تجاهلها.
4343

44-
More in: <info:structure>.
44+
للمزيد من التفاصيل: <info:structure>.
4545

46-
## Strict mode
46+
## الوضع الدقيق (الصارم) (Strict mode)
4747

48-
To fully enable all features of modern JavaScript, we should start scripts with `"use strict"`.
48+
لتمكين وتفعيل جميع ميزات الإصدار الحديث من جافاسكريبت، يجب علينا بدء أي ملف لبرنامج معين بـِ `"use strict"`.
4949

5050
```js
5151
'use strict';
5252

5353
...
5454
```
5555

56-
The directive must be at the top of a script or at the beginning of a function body.
56+
يجب وضع هذه التعليمة أو التوجيه في أعلى النص البرمجي أو في بداية جسم التابع.
5757

58-
Without `"use strict"`, everything still works, but some features behave in the old-fashion, "compatible" way. We'd generally prefer the modern behavior.
58+
وبدون وضع التعليمة `"use strict"`، سيعمل كل شيء على ما يرام، ولكن ستعمل بعض الميزات بأسلوبها القديم المتوافق مع السلوك الحديث. لذلك يُفضل عموماً استخدام هذا الأسلوب الأحدث.
5959

60-
Some modern features of the language (like classes that we'll study in the future) enable strict mode implicitly.
60+
جديرٌ بالذكر، أن بعضاً من هذه الميزات (كالصفوف التي سندرسها في المستقبل) تقوم بتفعيل هذا الوضع الحديث (الدقيق) بشكل ضمني حتى لو لم يتم كتابة التعليمة بشكل صريح.
6161

62-
More in: <info:strict-mode>.
62+
للمزيد من المعلومات: <info:strict-mode>.
6363

64-
## Variables
64+
## المتحولات (المتغيرات)
6565

66-
Can be declared using:
66+
يُمكن تعريفها كالتالي:
6767

6868
- `let`
69-
- `const` (constant, can't be changed)
70-
- `var` (old-style, will see later)
69+
- `const` (ثابت، لا يمكن تغيير قيمته)
70+
- `var` (باستخدام الأسلوب القديم، كما سنراه لاحقاً)
7171

72-
A variable name can include:
73-
- Letters and digits, but the first character may not be a digit.
74-
- Characters `$` and `_` are normal, on par with letters.
75-
- Non-Latin alphabets and hieroglyphs are also allowed, but commonly not used.
72+
يمكن أن يحتوي اسم المتحول على:
73+
- الحروف والأرقام، ولكن بشرط ألا يكون المحرف الأول رقماً.
74+
- تعتبر المحارف `$` و `_` طبيعية، وتعامل مثلها كمثل الحروف.
75+
- يُسمح أيضاً بالأبجدية الهيروغليفية غير اللاتينية، ولكن عادةً لا يتم استخدامها.
7676

77-
Variables are dynamically typed. They can store any value:
77+
المتغيرات هي ديناميكية النمط. أي يمكن تخزين أي قيمة فيها:
7878

7979
```js
8080
let x = 5;
8181
x = "John";
8282
```
8383

84-
There are 8 data types:
84+
وهناك 8 أنواع من أنماط البيانات:
8585

86-
- `number` for both floating-point and integer numbers,
87-
- `bigint` for integer numbers of arbitrary length,
88-
- `string` for strings,
89-
- `boolean` for logical values: `true/false`,
90-
- `null` -- a type with a single value `null`, meaning "empty" or "does not exist",
91-
- `undefined` -- a type with a single value `undefined`, meaning "not assigned",
92-
- `object` and `symbol` -- for complex data structures and unique identifiers, we haven't learnt them yet.
86+
- `number` لكل من الأرقام العشرية والأرقام الصحيحة،
87+
- `bigint` للأرقام الصحيحة غير محددة الطول،
88+
- `string` لسلاسل المحارف,
89+
- `boolean` للقيم المنطقية: `true/false`,
90+
- `null` -- وهو نوع بقيمة واحدة وهي `null`, وتعني "فارغ" أو "غير موجود",
91+
- `undefined` -- وهو نوع بقيمة واحدة وهي `undefined`, وتعني "غير مُسند",
92+
- `object` و `symbol` -- وتستخدم لبُنى المعطيات المعقدة والمُعرّفات الفريدة أو غير المتكررة، ولم نتطرق لذكر هذه الأنماط بعد.
9393

94-
The `typeof` operator returns the type for a value, with two exceptions:
94+
يُعيد العامل `typeof` النمط الخاص بقيمة معيّنة، باستثناء الحالتين التالييتين:
9595
```js
96-
typeof null == "object" // error in the language
97-
typeof function(){} == "function" // functions are treated specially
96+
typeof null == "object" // خطأ في اللغة
97+
typeof function(){} == "function" // يتم معالجة التوابع بشكل خاص
9898
```
9999

100-
More in: <info:variables> and <info:types>.
100+
للمزيد من التفاصيل: <info:variables> وَ <info:types>.
101101

102-
## Interaction
102+
## التفاعل مع المتصفح
103103

104-
We're using a browser as a working environment, so basic UI functions will be:
104+
نحن نستخدم المتصفح كبيئة عمل، لذا تكون واجهات المستخدم الأساسية للتفاعل معه هي:
105105

106106
[`prompt(question, [default])`](mdn:api/Window/prompt)
107-
: Ask a `question`, and return either what the visitor entered or `null` if they clicked "cancel".
107+
: عن طريق هذه التعليمة يتم طرح سؤال على المستخدم، مع حقل نصّي لإدخال الجواب المناسب، فيتم إرجاع القيمة التي أدخلها المستخدم أو `null` إذا نقر على زر الإلغاء (cancel).
108108

109109
[`confirm(question)`](mdn:api/Window/confirm)
110-
: Ask a `question` and suggest to choose between Ok and Cancel. The choice is returned as `true/false`.
110+
: تقوم هذه التعليمة بطرح سؤال مع إمكانية الجواب بموافق (Ok) أو إلغاء (Cancel). وبحسب الاختيار يتم إرجاع قيمة `false/true`.
111111

112112
[`alert(message)`](mdn:api/Window/alert)
113-
: Output a `message`.
113+
: تقوم هذه التعليمة بإظهار رسالة معيّنة `message`.
114114

115-
All these functions are *modal*, they pause the code execution and prevent the visitor from interacting with the page until they answer.
115+
جميع التوابع السابقة هي عبارة عن ملاحظات شكلية أي يتم فتح نافذة صغيرة في أعلى الصفحة نفسها وتقوم بعرض السؤال، فتقوم هذه الملاحظة بإيقاف تنفيذ الكود البرمجي وتمنع المستخدم من التفاعل مع الصفحة حتى تتم الإجابة على السؤال المطروح.
116116

117-
For instance:
117+
على سبيل المثال:
118118

119119
```js run
120120
let userName = prompt("Your name?", "Alice");
@@ -124,61 +124,61 @@ alert( "Visitor: " + userName ); // Alice
124124
alert( "Tea wanted: " + isTeaWanted ); // true
125125
```
126126

127-
More in: <info:alert-prompt-confirm>.
127+
للمزيد من التفاصيل: <info:alert-prompt-confirm>.
128128

129-
## Operators
129+
## العوامل
130130

131-
JavaScript supports the following operators:
131+
تدعم جافاسكريبت العوامل التالية:
132132

133-
Arithmetical
134-
: Regular: `* + - /`, also `%` for the remainder and `**` for power of a number.
133+
العوامل الرياضية
134+
: العوامل النظامية المعروفة كـَ `* + - /`، بالإضافة لـِ `%` لحساب باقي القسمة و `**` لحساب قوى أو أسّ عدد معين.
135135

136-
The binary plus `+` concatenates strings. And if any of the operands is a string, the other one is converted to string too:
136+
يقوم العامل الرياضي `+` بضم سلاسل المحارف أيضاً (strings). وفي حال كان أي من المعاملات (طرفي العامل) من نمط سلسلة محارف، يتم تحويل نمط الطرف الآخر لسلسلة محارف أيضاً في حال لم يكن كذلك:
137137

138138
```js run
139139
alert( '1' + 2 ); // '12', string
140140
alert( 1 + '2' ); // '12', string
141141
```
142142

143-
Assignments
144-
: There is a simple assignment: `a = b` and combined ones like `a *= 2`.
143+
الإسناد
144+
: الإسناد البسيط هو من الشكل: `a = b` أما الإسناد المركّب فهو من الشكل `a *= 2`.
145145

146-
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.
146+
عوامل البِتّات (Bitwise)
147+
: تقوم عوامل الـ Bitwise بالعمل مع الأعداد الصحيحة من فئة 32-بِت على الأقل، فهي تعمل على مستوى البِت، وللاطلاع عليها يمكن مراجعة [التوثيق](mdn:/JavaScript/Reference/Operators/Bitwise_Operators) عند الحاجة.
148148

149-
Conditional
150-
: The only operator with three parameters: `cond ? resultA : resultB`. If `cond` is truthy, returns `resultA`, otherwise `resultB`.
149+
العوامل الشرطية
150+
: والعامل الشرطي هو العامل الوحيد الذي يأخذ ثلاث معاملات: `cond ? resultA : resultB`. فإذا كان الشرط `cond` صحيحاً، سيتمّ إرجاع `resultA` وإلا سيتم إرجاع `resultB`.
151151

152-
Logical operators
153-
: Logical AND `&&` and OR `||` perform short-circuit evaluation and then return the value where it stopped (not necessary `true`/`false`). Logical NOT `!` converts the operand to boolean type and returns the inverse value.
152+
العوامل المنطقية
153+
: تقوم العوامل المنطقية AND `&&` وَ OR `||` باختصار عملية تقييم الكود البرمجي وإرجاع تلك القيمة حيث توقفت (وليس بالضرورة أن تكون تلك القيمة `true/false`). أما النفي المنطقي NOT `!` فيقوم بتحويل المعامل المُمرّر إلى نمط boolean ويرد القيمة المعاكسة له (نفي الشرط أو عكسه).
154154

155-
Nullish coalescing operator
156-
: The `??` operator provides a way to choose a defined value from a list of variables. The result of `a ?? b` is `a` unless it's `null/undefined`, then `b`.
155+
عامل دمج القيم الفارغة (غير الموجودة)
156+
: يقدّم العامل `??` طريقة لاختيار قيمة محدّدة بين قائمة من المتحولات (المتغيرات). فنتيجة التعبير التالي `a ?? b` هي قيمة `a` ما لم تكن قيمته `null/undefined`، وإلا قيمة `b`.
157157

158-
Comparisons
159-
: Equality check `==` for values of different types converts them to a number (except `null` and `undefined` that equal each other and nothing else), so these are equal:
158+
المقارنات
159+
: يقوم عامل التحقق من المساواة `==` للأنماط المختلفة بتحويل المعاملات لنمط رقم (number) (مالم تكن `null` أو `undefined` والتي تتساوى مع بعضها البعض ولا شي آخر يتساوى معها)، وبناءً عليه تعتبر التعابير التالية متساوية:
160160

161161
```js run
162162
alert( 0 == false ); // true
163163
alert( 0 == '' ); // true
164164
```
165165

166-
Other comparisons convert to a number as well.
166+
والمقارنات الأخرى تتحوّل لرقم أيضاً.
167167

168-
The strict equality operator `===` doesn't do the conversion: different types always mean different values for it.
168+
في حين لا يقوم عامل المقارنة الدقيق `===` بالتحويل: أي أن الأنماط المختلفة تعني وجود قيم مختلفة دائماً.
169169

170-
Values `null` and `undefined` are special: they equal `==` each other and don't equal anything else.
170+
أما القيم `null` و `undefined` فلها وضعٌ خاص: حيث تتساوى مع بعضها البعض عن طريق عامل المقارنة `==` ولا تتساوى مع أي شيء آخر.
171171

172-
Greater/less comparisons compare strings character-by-character, other types are converted to a number.
172+
تقوم مقارنات الـ أكبر/أصغر بمقارنة سلسلة المحارف محرف محرف، في حين باقي الأنماط يتم تحويلها لنمط الرقم (number).
173173

174-
Other operators
175-
: There are few others, like a comma operator.
174+
عوامل أخرى
175+
: هناك عوامل أخرى كذلك، كعامل الفاصلة.
176176

177-
More in: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nullish-coalescing-operator>.
177+
للمزيد من التفاصيل: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nullish-coalescing-operator>.
178178

179-
## Loops
179+
## الحلقات التكرارية
180180

181-
- We covered 3 types of loops:
181+
- كنا قد قمنا سابقاً بتغطية ثلاثة أنواعٍ للحلقات:
182182

183183
```js
184184
// 1
@@ -197,25 +197,25 @@ More in: <info:operators>, <info:comparison>, <info:logical-operators>, <info:nu
197197
}
198198
```
199199

200-
- The variable declared in `for(let...)` loop is visible only inside the loop. But we can also omit `let` and reuse an existing variable.
201-
- Directives `break/continue` allow to exit the whole loop/current iteration. Use labels to break nested loops.
200+
- يكون المتحول المعرف ضمن `for(let...)` مرئياً فقط داخل الحلقة. ولكن بإمكاننا حذف `let` وإعادة استخدام متحول معرّف قبل ذلك.
201+
- تسمح التعمليات `break/continue` بالخروج من الحلقة بشكل كامل أو من التكرار الحالي فقط. يمكنك استخدامها لكسر الحلقات التكرارية المتداخلة.
202202

203-
Details in: <info:while-for>.
203+
للمزيد من التفاصيل: <info:while-for>.
204204

205-
Later we'll study more types of loops to deal with objects.
205+
سنقوم لاحقاً بدراسة المزيد من أنواع الحلقات التكرارية والتي تتعامل مع الأغراض (الكائنات).
206206

207-
## The "switch" construct
207+
## جملة "switch"
208208

209-
The "switch" construct can replace multiple `if` checks. It uses `===` (strict equality) for comparisons.
209+
يمكن أن تحلّ البنية البرمجية "switch" محلّ العديد من التحققات المبنية باستخدام `if`. حيث تستخدم عامل المقارنة الدقيق `===` للتحقق من القيم الممررة.
210210

211-
For instance:
211+
على سبيل المثال:
212212

213213
```js run
214214
let age = prompt('Your age?', 18);
215215
216216
switch (age) {
217217
case 18:
218-
alert("Won't work"); // the result of prompt is a string, not a number
218+
alert("Won't work"); // نتيجة أو خرج التابع السابق هو من نمط سلسلة من المحارف وليس برقم
219219
break;
220220
221221
case "18":
@@ -227,13 +227,13 @@ switch (age) {
227227
}
228228
```
229229

230-
Details in: <info:switch>.
230+
للمزيد من التفاصيل: <info:switch>.
231231

232-
## Functions
232+
## الدوال (التوابع)
233233

234-
We covered three ways to create a function in JavaScript:
234+
كنا قد قمنا بتغطية ثلاثة أنواع لإنشاء الدوال في جافاسكريبت:
235235

236-
1. Function Declaration: the function in the main code flow
236+
1. تعريف الدالة: حيث تكون الدالة موجودة ضمن نطاق التنفيذ الأساسي
237237

238238
```js
239239
function sum(a, b) {
@@ -243,7 +243,7 @@ We covered three ways to create a function in JavaScript:
243243
}
244244
```
245245

246-
2. Function Expression: the function in the context of an expression
246+
2. الدوال كتعابير: حيث تكون الدوال موجودة ضمن سياق تعبير عادي وليس كتعريف كما سبق
247247

248248
```js
249249
let sum = function(a, b) {
@@ -253,32 +253,33 @@ We covered three ways to create a function in JavaScript:
253253
};
254254
```
255255

256-
3. Arrow functions:
256+
3. الدوال كأسهم: (حيث تُرسم الدوال بطريقة تشبه شكل السهم)
257257

258258
```js
259-
// expression at the right side
259+
// توضع التعابير في الطرف اليميني
260260
let sum = (a, b) => a + b;
261261
262-
// or multi-line syntax with { ... }, need return here:
262+
// أو يمكن استخدام أكثر من سطر مع أقواس الكتل {...}
263+
// ولكن سنحتاج لتعليمة return هنا:
263264
let sum = (a, b) => {
264265
// ...
265266
return a + b;
266267
}
267268
268-
// without arguments
269+
// بلا معاملات
269270
let sayHi = () => alert("Hello");
270271
271-
// with a single argument
272+
// مع معامل وحيد
272273
let double = n => n * 2;
273274
```
274275

275276

276-
- Functions may have local variables: those declared inside its body. Such variables are only visible inside the function.
277-
- Parameters can have default values: `function sum(a = 1, b = 2) {...}`.
278-
- Functions always return something. If there's no `return` statement, then the result is `undefined`.
277+
- يمكن أن تتضمن الدالة على متغيرات محلية: وهي المتغيرات التي يتم تعريفها ضمن جسم الدالة. وهذه المتغيرات تكون مرئية فقط ضمن الدالة نفسها.
278+
- يمكن أن تحتوي المعاملات على قيم افتراضية: ` {...} function sum(a = 1, b = 2)`.
279+
- تقوم الدوال بإرجاع قيمة دائماً. وإذا لم يكن هنالك تعليمة `return`، ستكون النتيجة هي `undefined`.
279280

280-
Details: see <info:function-basics>, <info:arrow-functions-basics>.
281+
للمزيد من التفاصيل: <info:function-basics>, <info:arrow-functions-basics>.
281282

282-
## More to come
283+
## المزيد قادم
283284

284-
That was a brief list of JavaScript features. As of now we've studied only basics. Further in the tutorial you'll find more specials and advanced features of JavaScript.
285+
كانت تلك قائمة مختصر بميزات جافاسكريبت، وحتى الآن قمنا بدراسة الأساسيات فقط. علاوةً على ذلك وفي البرنامج التعليمي، ستجد المزيد من الميزات الخاصة والمتقدمة لجافاسكريبت.

0 commit comments

Comments
 (0)