I’ve noticed that when you try to change a const value the Chrome Console console returns the following error:
Uncaught TypeError: Assignment to constant variable.
Are there any special reasons for calling a constant a “constant variable”? It seems paradoxical to me.
Advertisement
Answer
It’s because “variable” is a general term for a name that holds a value, common to most programming languages.
Also, the term “constant” by itself can be confusing, because it’s often used to refer to primitive, literal values like 1
and "foo"
.
So a “constant variable” is a variable that has been declared with a const
statement. Yes, it’s an oxymoron because the value can’t vary. But it acts the same as variables in all other respects. There’s no other common term for the thing that writable variables and constant variables have in common.