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 🙂
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
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!
But doing either of these will result in an error
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 🙂