1.4 KiB
1.4 KiB
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:
const someVar = "Hat";
function myFun() {
const 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
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;
}