Why are constants called "constant variable" in Google Chrome console?

Viewed 188

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.

2 Answers

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.

Nothing about the term variable implies mutability. It may hold varying values (e.g. during different runs of the program), but not necessarily be assignable. Notice that a variable in mathematics never changes its value either.

Related