Files
freeCodeCamp/curriculum/challenges/italian/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md
camperbot b3af21d50f chore(i18n,curriculum): update translations (#42487)
* chore(i18n,curriculum): update translations

* chore: Italian to italian

Co-authored-by: Nicholas Carrigan <nhcarrigan@gmail.com>
2021-06-14 11:34:20 -07:00

1.4 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56533eb9ac21ba0edf2244c0 Ambito globale e ambito locale nelle funzioni 1 https://scrimba.com/c/c2QwKH2 18194 global-vs--local-scope-in-functions

--description--

È possibile avere sia variabili locali che globali con lo stesso nome. Quando fai questo, la variabile locale ha la precedenza sulla variabile globale.

In questo esempio:

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

La funzione myFun restituirà la stringa Head perché è presente la versione locale della variabile.

--instructions--

Aggiungi una variabile locale alla funzione myOutfit per sovrascrivere il valore di outerWear con la stringa sweater.

--hints--

Non dovresti cambiare il valore della variabile globale outerWear.

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

myOutfit dovrebbe restituire la stringa sweater.

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

Non dovresti cambiare l'istruzione return.

assert(/return outerWear/.test(code));

--seed--

--seed-contents--

// Setup
var outerWear = "T-Shirt";

function myOutfit() {
  // Only change code below this line



  // Only change code above this line
  return outerWear;
}

myOutfit();

--solutions--

var outerWear = "T-Shirt";
function myOutfit() {
  var outerWear = "sweater";
  return outerWear;
}