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 trial

JavaScript JavaScript Foundations Variables Shadowing

After calling whosgotthefunc you get "Andrew" but then when you console.log(person) you would get Nick?

Because they are console.log person in the global scale, which is either "Jim" or "Nick" but the second person in the global scale (Nick) is just the original person with the value changed?

Zachary Green
Zachary Green
16,359 Points

Yep its all about the scope of the var. heres a short intro to scope https://www.youtube.com/watch?v=SBwoFkRjZvE

1 Answer

Ok, I believe your referring to the first question after the video. Because there is the keyword "var" in front of the variable name within the function "whosgotthefuc", the global variable "person" is not changed. If the word "var" wasn't there then the global variable "person" would change. Does that make sense?