Now that we learned about objects and arrays,
there's one common misconception I sometimes see in the Q & A section.
Please check out that video I linked earlier in this article where I talk about primitive and reference
types in Javascript because that is a crucial concept.
Objects and arrays are so-called reference types and you'll learn all about that and what that is in
the linked video
so I'm not going to re-explain it here.
They are reference types and therefore when I store an array in a constant hobbies, I can still edit
this array without violating the restriction that the constants must not change,
let me prove that to you. If I comment
that out and I add a new line here and I use another method,
the push method which allows me to add a new element to the existing array.
So this will not return a new array,
it will add it to the existing array
and here, I will add programming.
Now if I console log hobbies after pushing and I run node play.js, you'll see that's the output and we
get no error about editing this constant.
The reason for that is that reference types only store an address pointing at the place in memory where
that array is stored and that pointer this address has not changed by us adding a new element,
so the thing stored in this constant is just this pointer, just this address and this has not changed,
therefore our constant value has not changed. The thing it's pointing at has changed
but that totally does not matter here.
And this is something you have to understand so that you don't wonder what's going on
when we do edit in quotation marks a constant value.
We're not really editing a thing that is stored in a constant,
we're only editing the thing
that constant thing is pointing at.