Basic JavaScript - Global vs. Local Scope in Functions

Console.log returns “T-shirt” shouldn’t it return “sweater” since the local version of the variable is present.

Your code so far

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

function myOutfit() {
  // Only change code below this line
let outerWear = "sweater";
  // Only change code above this line
  return outerWear;
}

myOutfit();
console.log(outerWear)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Global vs. Local Scope in Functions

Link to the challenge:

You are only changing the value of that variable inside of the function.

Im confused then as to how the function is ran or accessed ? Can you use console.log on a function?

You can use console.log() to see the return value from a function:

console.log(myOutfit());
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.