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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![robinhickson](https://secure.gravatar.com/avatar/e6a81bf44c2f20fef2b72448600e111a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
robinhickson
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](https://uploads.teamtreehouse.com/production/profile-photos/8225832/micro_IMG_2910.jpg)
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.