Declare a Read-Only Variable with the const Keyword

Hello, how can const be a variable

hello, welcome to the forum.

Your question is very vague.
Please try to describe what you are struggling to understand in more detail.

1 Like

well Im doing the javascript course and in the part (Declare a Read-Only Variable with the const Keyword)
is saying that const is a variable and im not getting that

Please provide a link so we can see the reference.

1 Like

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword

thanks for the reference.
It doesn’t say that const is a variable in the reference you provided.
Instead it says:
you can also declare variables using the const keyword.

(just like you can declare a variable with let for example, const is a different keyword which basically says that the following variable name is constant)

1 Like

how declaring a variable with const
maybe im wrong but in math const is the opposite of variable
this is why i asked because i dont know maybe it means something else

ah I see your point now (this is why it helps to write down at the start what you are thinking so we are not talking at cross-purposes).

All variables are essentially pointers to blocks of memory that are used to store values that are interesting to the current program.
What const is doing, is that it is telling the compiler (I don’t know if you know about compilers?) that this section of memory is going to get a value and then never change.

So it is a keyword that reflects the intention of the programmer to not change this variable’s value (understanding that the word variable here is a pointer to memory and not like a math variable).

Once created, JS would give some kind of error if someone attempts to modify it.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.