Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md
2022-10-20 09:13:17 -07:00

1.7 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244c0 النطاق العام مقابل النطاق المحلي في الوظائف (Global vs. Local Scope in Functions) 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;
}