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

Damien Bactawar
Damien Bactawar
5,544 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
177,495 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
5,544 Points

Thanks for sharing the knowledge.

Steven Parker
Steven Parker
177,495 Points

Damien Bactawar — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!