There are 6 primitive data types: string, number, bigint, boolean, undefined, and symbol...
All primitives are immutable
So primitives already cannot change. let creates a binding that can be changed while a const binding cannot change.
However structural types like object (which includes arrays) and function are mutable. So the readonly reference of const to structural types doesn't influence their mutability. Internally the instance of a structural type remains mutable. However the const reference cannot be changed to refer to another value.
So it's not that value does not change (because in the case of an instance of a structural type it can) but the reference to the value cannot change.
let creates a reference that can be reassigned.
const creates a reference that cannot be reassigned.
i.e. that value is a place and the 456 replaces 123 in that place - when in fact value is simply a name that refers to the place where 123 is and that name can later refer to a different place where 456 is. So with
constvalue=123;
value can only ever refer to one and the same place - the one where 123 is.
See no turns to an expert at day 1. People have to then understand that is a reference and a value. Everything has a dependency. And just reading it once won't build a model. Everyone has to study, practice and learn regularly to get good at anything.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Actually
MDN: const
MDN: Primitive
So primitives already cannot change.
let
creates a binding that can be changed while aconst
binding cannot change.However structural types like
object
(which includes arrays) andfunction
are mutable. So the readonly reference ofconst
to structural types doesn't influence their mutability. Internally the instance of a structural type remains mutable. However theconst
reference cannot be changed to refer to another value.So it's not that value does not change (because in the case of an instance of a structural type it can) but the reference to the value cannot change.
let
creates a reference that can be reassigned.const
creates a reference that cannot be reassigned.Definitely. But when a person starts out you can't explain in such depth. And there are complex blogs so someone has to explain the easy way too :)
reinforces a faulty mental model
i.e. that
value
is a place and the456
replaces123
in that place - when in factvalue
is simply a name that refers to the place where123
is and that name can later refer to a different place where456
is. So withvalue
can only ever refer to one and the same place - the one where123
is.See no turns to an expert at day 1. People have to then understand that is a reference and a value. Everything has a dependency. And just reading it once won't build a model. Everyone has to study, practice and learn regularly to get good at anything.