freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../basic-javascript/global-vs.-local-scope-in-f...

1.8 KiB

id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244c0 Global vs. Local Scope in Functions 1 Ámbito global vs. local en funciones

Description

Es posible tener variables locales y globales con el mismo nombre. Cuando haces esto, la variable local tiene prioridad sobre la variable global . En este ejemplo:
var someVar = "Hat";
función myFun () {
var someVar = "Head";
devuelve someVar;
}
La función myFun devolverá "Head" porque la versión local de la variable está presente.

Instructions

Agregue una variable local a la función myOutfit para anular el valor de outerWear con "sweater" .

Tests

tests:
  - text: No cambie el valor de la <code>outerWear</code> global
    testString: 'assert(outerWear === "T-Shirt", "Do not change the value of the global <code>outerWear</code>");'
  - text: <code>myOutfit</code> debe devolver <code>&quot;sweater&quot;</code>
    testString: 'assert(myOutfit() === "sweater", "<code>myOutfit</code> should return <code>"sweater"</code>");'
  - text: No cambie la declaración de devolución
    testString: 'assert(/return outerWear/.test(code), "Do not change the return statement");'

Challenge Seed

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

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



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

myOutfit();

Solution

// solution required