* fix: restructure certifications guide articles * fix: added 3 dashes line before prob expl * fix: added 3 dashes line before hints * fix: added 3 dashes line before solutions
931 B
931 B
title
title |
---|
Global vs. Local Scope in Functions |
Global vs. Local Scope in Functions
Hints
Hint 1
Remember that global scope means that the variable is available throughout the entire code. Local scope, means that the variable is available within a certain range.
In this exercise, you have an outerWear
variable in global scope with "T-shirt" as its value. You should now create another variable named outerWear
, but this time within the function myOutfit()
. The basic code solution is as follows:
Solution 1 (Click to Show/Hide)
var outerWear = "T-Shirt";
function myOutfit() {
var outerWear = "sweater";
return outerWear;
}
myOutfit();
Code Explanation
- The function will return the closest
outerWear
it can find. Since we created anouterWear
inside the function, that is the 'closest', so the function will return "sweater".