1.4 KiB
1.4 KiB
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244c0 | Diferenciar escopo global e local em funções | 1 | https://scrimba.com/c/c2QwKH2 | 18194 | global-vs--local-scope-in-functions |
--description--
É possível ter as variáveis local e global com o mesmo nome. Quando você faz isso, a variável local tem precedência sobre a variável global.
Neste exemplo:
const someVar = "Hat";
function myFun() {
const someVar = "Head";
return someVar;
}
A função myFun
retornará a string Head
porque a versão local da variável está presente.
--instructions--
Adicione uma variável local para a função myOutfit
para sobrescrever o valor de outerWear
com a string sweater
.
--hints--
Você não deve alterar o valor da variável global outerWear
.
assert(outerWear === 'T-Shirt');
myOutfit
deve retornar a string sweater
.
assert(myOutfit() === 'sweater');
Você não deve alterar a instrução de retorno.
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;
}