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
That's very similar to OR `||` operator. Actually, we can replace`??`with`||`in the code above and get the same result.
34
+
هذا مشابه جدًا للمعامل `||`. في الحقيقة يمكننا استبدال`??`ب`||`في المثال السابق وسنحصل على نفس النتيجة.
35
35
36
-
The important difference is that:
37
-
- `||`returns the first *truthy* value.
38
-
- `??`returns the first *defined* value.
36
+
الفرق الجوهري بينهما أن:
37
+
- `||`يرجع أول قيمة *truthy*.
38
+
- `??`يرجع أول قيمة *defined*.
39
39
40
-
This matters a lot when we'd like to treat `null/undefined`differently from`0`.
40
+
هذا مهم جدًا عندما نريد معاملة `null/undefined`بطريقة مختلفة عن`0`.
41
41
42
-
For example:
42
+
مثلًا:
43
43
44
44
```js
45
45
height = height ??100;
46
46
```
47
47
48
-
This sets`height`to`100`if it's not defined. But if `height`is`0`, then it remains "as is".
48
+
هذا يجعل`height`يساوي`100`إذا لم يعرف. ولكن إذا كان `height`يساوي`0` سيبقى كما هو.
49
49
50
-
Let's compare it with`||`:
50
+
لنقارنه مع`||`:
51
51
52
52
```js run
53
53
let height =0;
@@ -56,62 +56,62 @@ alert(height || 100); // 100
56
56
alert(height ??100); // 0
57
57
```
58
58
59
-
Here,`height ||100`treats zero height as unset, same as `null`, `undefined`or any other falsy value, depeding on use cases that may be incorrect.
59
+
هنا`height ||100`تعامل الصفر مثل `null`, `undefined`أو أي قيمة falsy أخرىوهذا قد لا يكون صحيح أحيانًا.
60
60
61
-
The`height ??100`returns`100`only if `height`is exactly`null`or`undefined`.
61
+
ولكن`height ??100`ترجع`100`إذا كان فقط `height`يساوي تمامًا`null`أو`undefined`.
62
62
63
-
## Precedence
63
+
## الأولوية
64
64
65
-
The precedence of the `??`operator is rather low: `7`in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table).
0 commit comments