DEV Community

Discussion on: What JavaScript do you need to know to write Single-Page-Applications more effectively: A Guide

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

Nice post.....

I don't understand the the const variable explanation...or is it a typo?

Collapse
 
rjzauner profile image
RoryJZauner

Thank you for your reply - I tried to make the explanation a touch easier to understand, but I guess it ended up being more confusing 😅

Collapse
 
peerreynders profile image
peerreynders

Probably should have been

these are variables whose value will not change over time.

but even that isn't correct.

Quote

The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its properties) can be altered.

The wrinkle is that

Quote:

All types except objects define immutable values (that is, values which can't be changed). For example (and unlike in C), Strings are immutable. We refer to values of these types as "primitive values".

This gives people the impression that const works differently for primitive values and objects - it's just that the binding is immutable - not the value which why you can still modify the internals of objects (and arrays which are objects).

Collapse
 
rjzauner profile image
RoryJZauner

Thank you for helping me out! Awesome explanation!