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 Basics (Retired) Making Decisions with Conditional Statements The Conditional Challenge Solution

Gregory Ledger
Gregory Ledger
6,116 Points

I put the starting score to 0 further down in my code

All the examples seem to put the starting "score" variable set to 0 at the beginning of the script. I put mine after all the question prompts. Does it matter? Why might putting it at the top be considered cleaner code?

1 Answer

Schaffer Robichaux
Schaffer Robichaux
21,729 Points

Hey Gregory,

As you alluded to in the end of your question, it is a best practice to declare your var/let/const variables in the beginning of your code. Although the practice may have little to no effect on personal or small projects, it can be a nightmare for someone to assist with debugging / collaboration as code bases grow larger. I personally couldn't put it any better than w3schools best practices ( https://www.w3schools.com/js/js_best_practices.asp )which states that putting declarations on top will: Give cleaner code Provide a single place to look for local variables Make it easier to avoid unwanted (implied) global variables Reduce the possibility of unwanted re-declarations

Hope this helps