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 trialDejan Antic
4,309 PointsWhy are we re-declaring the input and the span variables in the second if else statement?
I'm not sure I understand why we are redeclaring the input and the span variables again. Since we used CONST to declare them in the first ELSE IF block, how come we can change their values in the second ELSE IF block.
I hope the question is understandable :D
Dejan
3 Answers
Steven Parker
231,269 PointsA const
has block scope.
This means that the one declared in the first block cannot be accessed from the second block. So while the second block may be re-using the name, the variable itself is completely different from the one in the first block.
Dejan Antic
4,309 PointsThanks Steven! :)
So, if I understand correctly, const
and let
both have block scope, while var
doesn't have block scope?
Steven Parker
231,269 PointsYou got it. A var
has function scope instead.
Roudy Antenor
4,124 PointsBig Thanks Steven - Hey Dejan i had the same question- many Thanks for asking it first!