Most people don't understand that when it comes to learning, the most important is not be absolutely true but to make connection between notions.
Can you tell me why almost every article/tuto/course I found by googling "What's a variable" explains constant as "a type of variables"? By doing that we tell the readers that what he just learned with variables is still valid for constants but one thing changes: he can't change the value of a constant. He doesn't have to know more when he just started to learn to code.
Also, what I find interesting in the JS documentation is the sentence:
The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable, just that the variable identifier cannot be reassigned.
Not at all - it is a constant holding (or having a reference to) one 'thing'. The fact that the thing can be changed internally doesn't mean it isn't still the same 'thing' (like if I change my shoes from blue to red, I'm still me). The 'thing' that the constant is 'storing' cannot be changed to a different 'thing'.
This is the fundamental difference between 'variables' and 'constants' and should be taught right from the start so as to avoid any confusion later. It isn't difficult, the names describe the behaviour. A variable is variable, a constant stays constant
The issue is with referring to a constant as a variable. This is simply wrong and generates unnecessary confusion. Your description of the behaviour of a constant however, is completely acceptable
Then, you can start a proposal to change that in the TC39 and Ecma 262 specifications because they are currently referring to a constant as a variable:
let and const declarations define variables that are scoped to the running execution context's LexicalEnvironment.
A javascript specification (that defines at a technical level the way a const is implemented in the language) and how best to teach programming concepts to beginners are 2 entirely different things :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
const
defines a constant. Constants are not variables. The clue is in the names:In Javascript
const
is a bit misleading. It does not define a constant, but it's a one-time assignment. It's a constant reference to a value.Because of this you can not change constant primitive values, but you can change properties of a constant object.
Most people don't understand that when it comes to learning, the most important is not be absolutely true but to make connection between notions.
Can you tell me why almost every article/tuto/course I found by googling "What's a variable" explains constant as "a type of variables"? By doing that we tell the readers that what he just learned with variables is still valid for constants but one thing changes: he can't change the value of a constant. He doesn't have to know more when he just started to learn to code.
Also, what I find interesting in the JS documentation is the sentence:
It seems like, here, a constant is a variable.
Not at all - it is a constant holding (or having a reference to) one 'thing'. The fact that the thing can be changed internally doesn't mean it isn't still the same 'thing' (like if I change my shoes from blue to red, I'm still me). The 'thing' that the constant is 'storing' cannot be changed to a different 'thing'.
This is the fundamental difference between 'variables' and 'constants' and should be taught right from the start so as to avoid any confusion later. It isn't difficult, the names describe the behaviour. A variable is variable, a constant stays constant
When the article say:
It's not clear enough?
The issue is with referring to a constant as a variable. This is simply wrong and generates unnecessary confusion. Your description of the behaviour of a constant however, is completely acceptable
Then, you can start a proposal to change that in the TC39 and Ecma 262 specifications because they are currently referring to a constant as a variable:
source: tc39.es/ecma262/#sec-let-and-const...
A javascript specification (that defines at a technical level the way a
const
is implemented in the language) and how best to teach programming concepts to beginners are 2 entirely different things :)