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 trialAdam Wilson
6,293 PointsUsing comments to define/clarify variables
Is it bad practice to define a variable as something easily typed, such as 'pn' for 'playerName' or 'sc' for 'score' and then use a comment to clarify what the variable means?
Example: var pn = "name"; //pn = Player Name
2 Answers
Antti Lylander
9,686 PointsThere is very little point in making variables easy to type and difficult to identify. Most text editors can suggest completion after you have started to type the variable name. Also, you will not write it so many times anyways. When your code becomes more complex, you will value descriptive variable names.
Daniel Boisselle
Front End Web Development Techdegree Student 17,438 PointsI would argue that you want your code to be easily understood without comments.
ex:
var PlayerName = "Adam Wilson"