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!
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
Invalid JS code questions
The question is something like; which is invalid code, and one of the answers (fortunately the least right answer) is constweeksPerYear = 52. But is this strictly true? Is this really invalid code? I could have declared constweeksPerYear as a variable earlier, and now changed the value to 52. Surely this is not invalid, just because of the letters const at the beginning of the variable name? Not good, not clever name for a variable, I know, but invalid??
The quiz is not saying the
constweeksPerYear is invalid because of the keywork at the start, this is valid. It is saying it is invalid because there is no space between
You are right in that you will not get an error (unless your in strict mode) as you can create a variable without a prefix in JS, although not recommended and you definitely should not do it.
Given that every other example uses the variable prefix of
const it is correct to assume that the invalid one is the one without the space
constweeksPerYear as a typo.