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 trialillhueminati
41 PointsThe declaration of variables and var
Noticed in the one of the code alongs there was a var name.
This has always been a mixed bag talking to people about it. In computer science at university, var was still acceptable, lot of the old school professors were onboard with it. Jump to online dev communities, whether it be YouTube or Discord, using var is a sin. Looking through stack and top rated answers from this year, var is still being implemented.
Is there a reason it's so polarising, should it be used, should it no be used? Difficult to find a source I can trust I guess. Thanks for any information!
1 Answer
Steven Parker
231,198 PointsUltimately I think it comes down to programming style. You get to choose whether to use it or not. Or if you work for an employer, they may provide you with coding standards that explicitly say when (or if) it can be used.
I personally like to use it for globals, to make their intention obvious. I also use it to create variables in the console, since the scope of the newer declarations can be too restrictive.