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 Numbers Working with Numbers Doing Basic Math

Need clarification

"The let keyword allows you to add to the current value of score." - could you please elaborate what you mean by this

2 Answers

I think the course tutor means that they are using a let statement rather than a const statement in that context. Neither a let or const statement can be re-declared in a JS document, but the let value can be re-assigned/altered. Thus in the context of a game which keeps track of a player's score, you would use a let variable over a const as a container for the score, as the value would need to be updated as the game runs based on player actions.

There was a brief use of this case as an example in the JS Basics course, which was run by the same tutor, when he introduced let and const variables as an alternative to vars.

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

I am not sure what the author was intending with that statement, but "let" is used to declare a particular name to be a variable. In JavaScript code you will see both "var" and "let" as declaration statments-- "let" is the modern version "block-level" version.

When you get to a bit more advanced level of JavaScript you will see that "var" declares a global scope (or functional scope) of a variable, and "let" is always considered as a block scope -- for now, it isn't important to understand the subtle issues with that because it will be covered in more advanced JavaScript courses at Treehouse.

The definitive documentation on "let" is at Mozilla Developer Network.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let