Earlier quoted context omitted.
It doesn't help that many variables are objects, and const means that you cannot reassign the variable, not that you cannot modify it. e.g. const x = {}; x.foo = 'it works!'
`const` means that the variable binding itself is immutable. It only affects the variable binding, not the value it points to. If it affected the value it pointed to, what would happen in this type of situation? let x = {}; const y = x; x.a = 5;
The answer is it works fine. x.a === y.a === 5
This is because you are simply declaring the binding of y to the object bound to x constant. This does not impact your ability to rebind x or to alter the contents of the object, it simply prevents you from rebinding y.
let x = {a:5}
x = {}
console.log(x.a) // undefined
--- const y = {a:5}
y = {} // Uncaught TypeError: Assignment to a constant variable.
--- let x = {a:2}
const y = x
x.b = 12
x = {}
x.b = 13
console.log(y) // {a: 2, b:12}
console.log(x) // {b: 13}