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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ali Dahud](https://secure.gravatar.com/avatar/5073087b3e7ad98fbe390d6d9c1347bb?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ali Dahud
3,459 PointsCan you explain to me in more depth?
what is a variable scope? because in the video it's explained poorly Steven Parker
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsSure, I'll give it a shot, but for future questions try giving the whole community some time to answer before tagging anyone specifically. There are lots of folks wiling to help.
So "variable scope" is basically a way to describe what part of the program a variable can be accessed in. The most common cases are "global scope", which means the variable can be accessed anywhere, "function scope" where the variable can be accessed only within a specific function, and "block scope" where the variable can be accessed only inside a code block (between a pair of braces {}). Here's some examples:
var globby = 2; // global scope
function test(x) {
if (x == 1) {
var funky = 3; // function scope
let blocky = 4; // block scope
console.log(typeof globby); // "number"
console.log(typeof funky); // "number"
console.log(typeof blocky); // "number"
}
console.log(typeof globby); // "number"
console.log(typeof funky); // "number" (still in scope)
console.log(typeof blocky); // "undefined"
}
test(1);
console.log(typeof globby); // "number"
console.log(typeof funky); // "undefined"
console.log(typeof blocky); // "undefined"
Ali Dahud
3,459 PointsAli Dahud
3,459 PointsThank you but you’re so responsive and you’re explaining it extremely well.
Ali Dahud
3,459 PointsAli Dahud
3,459 PointsAnd if we can’t be in direct contact then why wouldn’t I?
Steven Parker
230,688 PointsSteven Parker
230,688 PointsThat's very nice, and I'm flattered. But I'm sure input from various sources would be beneficial to your learning. Give the community as a whole a chance.
Plus I do answer questions where I'm not tagged.![:wink: :wink:](https://image-proxy-cdn.teamtreehouse.com/2e760b3ad2356c698f6445aa940a24edfd675455/68747470733a2f2f7374617469632e7465616d74726565686f7573652e636f6d2f696d616765732f656d6f6a692f756e69636f64652f31663630392e706e67)