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 trialrobinhickson
Front End Web Development Techdegree Graduate 18,162 PointsInvalid 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??
1 Answer
Liam Clarke
19,938 PointsHello
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 const
and weeksPerYear
.
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.
robinhickson
Front End Web Development Techdegree Graduate 18,162 Pointsrobinhickson
Front End Web Development Techdegree Graduate 18,162 PointsYes, thanks - as I thought. I suppose it looks like I'm being pedantic; but just wanted to clarify whether the example
constweeksPerYear
was by definition somehow invalid: but it's not; it's just the least valid answer offered. i.e. it's poor coding, not necessarily invalid coding.