Files
freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-and-data-structures/basic-javascript/global-vs.-local-scope-in-functions.md

1.4 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
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 ambas 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:

var someVar = "Hat";
function myFun() {
  var 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
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;
}