DEV Community

loading...

Discussion on: let & const

Collapse
ceckenrode profile image
Christian Eckenrode

Awesome write up!

Just want to point out that if you have an array or an object declared with const, you can still modify them since they’ll still be pointing to the same value in memory. Example:

This is okay!

const person = {}
person.name = Christian

const hobbies = [playing guitar]
hobbies.push(drawing)

But doing either of these will result in an error

const person = {}
person = { name: Visakh }

const hobbies = []
hobbies = [coding]

So you can modify arrays an objects, but you can reassign them altogether (by resetting their value with the equals sign)

const in JavaScript doesn’t mean constant value, it means constant reference. See here.

You’re 100% correct when it comes to other primitive types though 🙂