Yes. If you think a variable won't change then use const. It can allow the javascript interpreter to optimise the code better. Also it prevents you accidentally overwriting it via a typo, for example.
If you add a line x=7 to your example you will see the editor warn you.
I know it can seem frustrating from your sdie of thigns. you explain something and I don't understand.
(Who's moved the keys on my keyboard?)
But it is good that I now have a fairly good understanding of what it all means.
Now I had better get back to what I am trying to do.
Again: It is hard to say WHO was the ultimate help.
If you are stuck with this problem, I'd suggest looking back at the demo flow I posted in reply 16 (I think)
It shows 4 examples.
const a_number =1;
const an_object = {};
const a_string = "asdfg";
const an_array =[];
a_number = 12; // error as changing value of const
a_string = "qwerty"; // error as changing value of const
an_object = 12; // an error because changing type of const
an_object = {"a":1}; // an error as assigning the var again.
an_object.a = 1; // no error as not assigning the var to an object, just adding a propperty
an_array = 12; // an error because changing type of const
an_array = [1]; // an error as assigning the var again.
an_array[0] = 1; // no error as not assigning the var to an array, just adding a propperty
If the object or array is static......
And is used for reference only.
Say a lookup table/array - to call it.
Like a table of tv stations that translates to their actual channel number.
That would be a const - yes?
I was (probably) over simplifying how I see it.
Which is not good.
But at my level I am wanting to take baby steps.
Ok, it can be amended also.
const x = {}
x.fred = "ooh!"
Over my head - sort of.
So you are making x into an array. And the pointer is called fred and it's value is "ooh!" fred seems a strange pointer. But I guess it isn't impossible.
I'm off to bed.
I lost 4 hours (there abouts) today with code and it all seeming to work then failing badly.
I think I've done enough today.
I'm making x into an OBJECT in that instance and the correct term rather than "pointer" is "property" but basically yes. And I often use "fred" and "jim" along with "foo" and "bah" - they are easy to type
For sure, you should always listen to what your body is telling you.
Lord! I thought you didn't want to be confused! The nightmare that is C/C++ is like Alice in Wonderland compared to JavaScript (which is bad enough, lets be honest).