Question about Local Scope and Function

Question about Local Scope and Function
0.0 0


So i passed a challenge regarding the Local Scopes. Im interested in why console.log(loc); is not defined?
is it because console.log(loc); is already inside of a function?I know it says its not defined since its outside of a function but this is confusing me.

Anothe question i wish to ask about return statements. I know return statement works when use return and name of a variable, but would it work if we used return with functions name? Can someone give me some tips of how exactly in different ways return statements work other than returning variables name?



That console.log( loc ); at the bottom won’t print what you expected because the variable loc was declared inside the function’s scope, between the curly braces. The first one, inside the function, will print “foo”, just like the example says, because its being executed through the function call.

This link might be helpful to you.

Happy coding!