A lot of devs coming from other languages assume const means constant value, whereas it's actually simply constant reference (i.e. can't reassign that variable).
You can't do
const a = 1
a = 2 // error!
but this is fine
const obj = {}
obj.newProp = 1
Check out Object.freeze if you want to prevent the value (objects, specifically) from being changed.
16
u/magical_h4x May 28 '19
A lot of devs coming from other languages assume
constmeans constant value, whereas it's actually simply constant reference (i.e. can't reassign that variable).You can't do
but this is fine
Check out Object.freeze if you want to prevent the value (objects, specifically) from being changed.