mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-02 12:03:49 -05:00
1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244c0 | المجال الشامل مقابل النطاق المحدد في الوظائف | 1 | https://scrimba.com/c/c2QwKH2 | 18194 | global-vs--local-scope-in-functions |
--description--
من الممكن الحصول على متغيرات محدودة (local) و شاملة (global) بنفس الاسم. عندما تقوم ذلك، يكون المتغير المحدود (local) له الأسبقية على المتغير الشامل (global).
وفي هذا المثال:
const someVar = "Hat";
function myFun() {
const someVar = "Head";
return someVar;
}
سوف تنتج الوظيفة myFun المقطع النصي Head لأن النسخة المحدودة (local) من المتغير موجودة.
--instructions--
أضف متغير محدود (local) إلى وظيفة myOutfit لتجاوز قيمة outerWear بالمقطع النصي sweater.
--hints--
لا يجب عليك تغيير قيمة المتغير الشامل (global) الآتي outerWear.
assert(outerWear === 'T-Shirt');
يجب أن ينتج myOutfit المقطع sweater.
assert(myOutfit() === 'sweater');
لا يجب عليك تغيير التعبير المنتج (return statement).
assert(/return outerWear/.test(code));
--seed--
--seed-contents--
// Setup
const outerWear = "T-Shirt";
function myOutfit() {
// Only change code below this line
// Only change code above this line
return outerWear;
}
myOutfit();
--solutions--
const outerWear = "T-Shirt";
function myOutfit() {
const outerWear = "sweater";
return outerWear;
}