You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of the time, operators and functions automatically convert the values given to them to the right type.
3
+
معظم الوقت، المعاملات و الدوال تحول أوتوماتيكياً تحول القيم المعطاة لهم للنوع الصحيح.
4
4
5
-
For example, `alert`automatically converts any value to a string to show it. Mathematical operations convert values to numbers.
5
+
على سبيل المثال ، `alert`تحول أوتوماتيكياً أي قيمة إلى نص لإظهاره. المعاملات الرياضية تحول القيم إلى أرقام.
6
6
7
-
There are also cases when we need to explicitly convert a value to the expected type.
7
+
هناك أيضاً حالات نحتاج إلى تصريح تحويل القيمة إلى النوع المطلوبة .
8
8
9
9
```smart header="Not talking about objects yet"
10
-
In this chapter, we won't cover objects. For now we'll just be talking about primitives.
10
+
في هذا الفصل ، لن نغطي الكائنات. الأن سوف نتحدث عن الأنواع الأساسية.
11
11
12
-
Later, after we learn about objects, in the chapter <info:object-toprimitive> we'll see how objects fit in.
12
+
فيما بعد ، بعد أن نتعلم عن الكائنات، في هذا الفصل <info:object-toprimitive> سنرى كيف الكائنات تتلائم فيه.
13
13
```
14
14
15
15
## String Conversion
16
16
17
-
String conversion happens when we need the string form of a value.
17
+
التحويل إلى نص يحدث عندما نحتاج الصورة النصية للقيمة.
18
18
19
-
For example, `alert(value)`does it to show the value.
19
+
على سبيل المثال ، `alert(value)`تفعل ذلك لإظهار القيمة.
20
20
21
-
We can also call the `String(value)`function to convert a value to a string:
21
+
نستطيع أيضاً إستدعاء دالة `String(value)`لكي نحول القيمة إلى نص:
22
22
23
23
```js run
24
24
let value =true;
25
25
alert(typeof value); // boolean
26
26
27
27
*!*
28
-
value =String(value); //now value is a string "true"
28
+
value =String(value); //الأن القيمة هي نص تساوي "true"
29
29
alert(typeof value); // string
30
30
*/!*
31
31
```
32
32
33
-
String conversion is mostly obvious. A`false`becomes`"false"`,`null`becomes`"null"`, etc.
33
+
التحويل إلى نص واضح جداً. `false`تصبح`"false"`و`null`تصبح`"null"`، إلخ.
34
34
35
35
## Numeric Conversion
36
36
37
-
Numeric conversion happens in mathematical functions and expressions automatically.
37
+
التحويل إلى رقم يتم أوتوماتيكياً في المعاملات والتعبيرات الرياضية.
38
38
39
-
For example, when division `/`is applied to non-numbers:
39
+
على سبيل المثال ، في حالة القسمة `/`عندما يتم تطبيقها على نوع غير رقمي:
40
40
41
41
```js run
42
-
alert( "6"/"2" ); // 3, strings are converted to numbers
42
+
alert( "6"/"2" ); // 3، النصوص تتحول إلى أرقام
43
43
```
44
44
45
-
We can use the `Number(value)`function to explicitly convert a `value`to a number:
45
+
نستطيع إستخدام دالة `Number(value)`للتصريح بتحويل القيمة `value`إلى رقم:
46
46
47
47
```js run
48
48
let str ="123";
49
49
alert(typeof str); // string
50
50
51
-
let num =Number(str); //becomes a number 123
51
+
let num =Number(str); //تصبح رقم 123
52
52
53
53
alert(typeof num); // number
54
54
```
55
55
56
-
Explicit conversion is usually required when we read a value from a string-based source like a text form but expect a number to be entered.
56
+
تصريح التحويل عادة يكون مطلوب عندما نقرأ قيمة من مصدر يعتمد على النص مثل حقل إدخال في نموذج لكن نتوقع أن يتم إدخال رقم .
57
57
58
-
If the string is not a valid number, the result of such a conversion is `NaN`. For instance:
58
+
لو النص ليس رقم صالح، ستكون النتيجة لمثل هذا التحويل هي `NaN`. على سبيل المثال:
59
59
60
60
```js run
61
61
let age =Number("an arbitrary string instead of a number");
62
62
63
-
alert(age); // NaN, conversion failed
63
+
alert(age); // NaN، التحويل فشل
64
64
```
65
65
66
-
Numeric conversion rules:
66
+
قواعد التحويل الرقمي:
67
67
68
-
|Value|Becomes... |
68
+
|القيمة|تصبح... |
69
69
|-------|-------------|
70
70
|`undefined`|`NaN`|
71
71
|`null`|`0`|
72
72
|<code>true and false</code> |`1` and `0`|
73
-
|`string`|Whitespaces from the start and end are removed. If the remaining string is empty, the result is `0`. Otherwise, the number is "read" from the string. An error gives `NaN`. |
73
+
|`string`|المساحات البيضاء في البداية والنهاية يتم إزالتها. لو باقي النص فارغ ، النتيجة هي `0`. غير ذلك، الرقم "يتم قرائته" من النص. أي خطأ يعطي`NaN`. |
74
74
75
-
Examples:
75
+
أمثلة:
76
76
77
77
```js run
78
78
alert( Number(" 123 ") ); // 123
79
-
alert( Number("123z") ); // NaN (error reading a number at "z")
79
+
alert( Number("123z") ); // NaN (خطأ في قراءة الرقم عند "z")
80
80
alert( Number(true) ); // 1
81
81
alert( Number(false) ); // 0
82
82
```
83
83
84
-
Please note that `null`and`undefined`behave differently here: `null`becomes zero while`undefined`becomes`NaN`.
84
+
من فضلك لاحظ أن `null`و`undefined`تسلك سلوك مختلف هنا: `null`تصبح صفر بينما`undefined`تصبح`NaN`.
85
85
86
-
Most mathematical operators also perform such conversion, we'll see that in the next chapter.
86
+
معظم المعاملات الرياضية أيضا تعمل مثل هذا التحويل ، سوف نرى ذلك في الفصل القادم .
87
87
88
88
## Boolean Conversion
89
89
90
-
Boolean conversion is the simplest one.
90
+
التحويل إلى قيم منطقية هو الأبسط.
91
91
92
-
It happens in logical operations (later we'll meet condition tests and other similar things) but can also be performed explicitly with a call to`Boolean(value)`.
92
+
إنه يحدث في معاملات منطقية (فيما بعد سنقابل إختبارات مشروطة وأشياء أخرى مشابهة ) لكن أيضاً يمكن تنفيذها تصريحياً عن طريق إستدعاء `Boolean(value)`.
93
93
94
-
The conversion rule:
94
+
قاعدة التحويل:
95
95
96
-
-Values that are intuitively "empty", like`0`, an empty string,`null`,`undefined`, and `NaN`, become`false`.
97
-
-Other values become`true`.
96
+
-القيم التي تكون حدسية "فارغة"، مثل`0`و نص فارغ و`null`و`undefined`و `NaN`تصبح`false`.
````warn header="Please note: the string with zero`\"0\"`is`true`"
110
-
Some languages (namely PHP) treat`"0"`as`false`. But in JavaScript, a non-empty string is always`true`.
109
+
````warn header="من فضلك لاحظ: النص المكون من صفر`\"0\"`يكون`true`"
110
+
بعض اللغات (أعني PHP) تعامل`"0"`ك`false`. لكن في الجافا سكربت ، النص غير الفارغ دائماً`true`.
111
111
112
112
```js run
113
113
alert( Boolean("0") ); // true
114
-
alert( Boolean("") ); //spaces, also true (any non-empty string is true)
114
+
alert( Boolean("") ); //المسافات، أيضاً true (أي نص غير فارغ يكون true)
115
115
```
116
116
````
117
117
118
118
## Summary
119
119
120
-
The three most widely used type conversions are to string, to number, and to boolean.
120
+
تحويلات الأنواع الثلاثة الأكثر إستخداماً هي إلى نص ، إلى رقم ، إلى قيمة منطقية .
121
121
122
-
**`String Conversion`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
122
+
**`التحويل للنص`** -- يحدث عندما نظهر شئ. يمكن تنفيذه عن طريق `String(value)`. التحويل إلى نص عادة واضح للقيم البسيطة .
123
123
124
-
**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`.
124
+
**`التحويل إلى رقم`** -- يحدث في المعاملات الرياضية. يمكن تنفيذها عن طريق `Number(value)`.
125
125
126
-
The conversion follows the rules:
126
+
التحويل يتبع القواعد:
127
127
128
-
| Value | Becomes... |
128
+
| القيمة | تصبح... |
129
129
|-------|-------------|
130
130
|`undefined`|`NaN`|
131
131
|`null`|`0`|
132
132
|<code>true / false</code> | `1 / 0` |
133
-
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
133
+
| `string` | يتم قراءة النص "كما هو"،المسافات البيضاء من الجانبين يتم تجاهلها. النص الفارغ يصبح `0`. الخطأ `NaN`. |
134
134
135
-
**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
135
+
**`التحويلات المنطقية`** -- يحدث في المعاملات المنطقية. يتم تنفيذه عن طريق `Boolean(value)`.
136
136
137
-
Follows the rules:
137
+
يتبع القواعد الأتية:
138
138
139
-
| Value | Becomes... |
139
+
| القيمة | تصبح... |
140
140
|-------|-------------|
141
141
|`0`, `null`, `undefined`, `NaN`, `""` |`false`|
142
-
|any other value| `true` |
142
+
|أي قيمة أخرى| `true` |
143
143
144
144
145
-
Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are:
145
+
معظم هذه القواعد سهل فهمها وحفظها. الإستثناءات الملحوظة عندما يفعل الناس عادة أخطاء وهي :
146
146
147
-
- `undefined` is `NaN` as a number, not `0`.
148
-
- `"0"` and space-only strings like `" "` are true as a boolean.
147
+
- `undefined` تكون `NaN` كرقم ليست `0`.
148
+
- `"0"` والنصوص التي تحتوي على مسافات فقط `" "` هي true كقيمة منطقية.
149
149
150
-
Objects aren't covered here. We'll return to them later in the chapter <info:object-toprimitive> that is devoted exclusively to objects after we learn more basic things about JavaScript.
150
+
لم يتم تغطية الكائنات هنا. سنعود إليهم لاحقاً في هذا الفصل <info:object-toprimitive> تكون مكرسة حصرياً للكائنات بعد أن تعمل أشياء أساسية أكثر عن الجافا سكربت .
0 commit comments