Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Getting Started With ES2015 Defining Variables With let and const Using let with for Loops

Damien Bactawar
Damien Bactawar
8,548 Points

Would, "const = 43;" still be classified as "variable declaration"? It sounds more like "constant declaration". LOL!

Just a light-hearted question however one wonders about the decisions the ECMA make. If people structure their code correctly is block level scope something that you have to worry about? Are they making developers live easier? Actually I'm just joking. I'm sure it is progress. I'm too junior to be making these judgments.

2 Answers

Steven Parker
Steven Parker
215,372 Points

Well, first off, "const = 43;" isn't valid syntax. You'd need to have an identifier name between the keyword "const" and the assignment operator, something like "const answer = 43;"

But yes, this is still referred to as a variable. A mathematician would argue that it's a constant and not a variable, but in programming lingo, it's a "variable" that happens to be "immutable" (or it has the property of being "constant").

And block scope does indeed make development easier (or at least less error-prone) once you're used to using it.

Damien Bactawar
Damien Bactawar
8,548 Points

Thanks for sharing the knowledge.