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
Renee Allen-Whindleton
5,857 PointsJavaScript variable declaration/initialization distinction - can you accomplish both in one step?
Thus far we have assigned values to “string” and numeric datatype variables in this JavaScript Basic module, but what about the preliminaries? Is declaring a value the same as initializing a value and if not, what is the distinction between the two? Lastly can you declare and initialize a variable all at the same time as I suspect this is probably what has occurred thus far. Seeking clarification before I begin “The Variable Challenge” - video time slot 2:55 minutes. I don’t recall this module discussing Declaration and Initialization of variables unless I missed something. Thanks in advance to whomever clarifies this for me?
2 Answers
Steven Parker
243,199 PointsThe difference between declaration and initialization is that the latter is a combination of a declaration and an assignment. Either way, it's just one step:
let weight; // declaration
const size = 23; // intialization
Renee Allen-Whindleton
5,857 PointsThanks Steven for the clarification and illustration. You confirmed my reasoning!
Steven Parker
243,199 PointsRenee Allen-Whindleton — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!