Files
freeCodeCamp/curriculum/challenges/korean/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md
freeCodeCamp's Camper Bot e6b05ee25d chore(i18n,learn): processed translations (#54537)
Co-authored-by: Naomi <nhcarrigan@gmail.com>
2024-04-26 12:26:37 +07:00

1.4 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--

It is possible to have both local and global variables with the same name. When you do this, the local variable takes precedence over the global variable.

In this example:

const someVar = "Hat";

function myFun() {
  const someVar = "Head";
  return someVar;
}

The function myFun will return the string Head because the local version of the variable is present.

--instructions--

Add a local variable to myOutfit function to override the value of outerWear with the string sweater.

--hints--

You should not change the value of the global outerWear.

assert(outerWear === 'T-Shirt');

myOutfit should return the string sweater.

assert(myOutfit() === 'sweater');

You should not change the return statement.

assert(/return outerWear/.test(__helpers.removeJSComments(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;
}