Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBla Blubb
2,740 Pointsnick is the correct answer. but why??
why is nick correct???
person="nick" was set outside the function. person was not called variable.
so it must end up in a failure notice: person is not defined.
or not???
1 Answer
William Li
Courses Plus Student 26,868 Pointsvar person = "Jim";
function whosGotTheFunc() {
var person = "Andrew";
}
person = "Nick";
whosGotTheFunc();
console.log(person);
Is this the code you're referring to? Nick
is certainly the correct answer. Let me say a couple things about it.
-
person
variable was declared in the first line,person = "Nick";
just reassign it a different value. - the statement
var person = "Andrew";
inside the functionwhosGotTheFunc
create another person variable local only to its function scope, which means this person variable is gone as soon as function invocation finished, and has nothing to do with the Global person variable outside of the function.