CodeNewbie Community 🌱

Discussion on: What's the difference between "let" and "const" in JavaScript?

Collapse
 
lyqht profile image
Estee Tey

To add on to the great explanation by @coderjoe82 , you need to be mindful of the case where you assign an object as a const, say

const user = { name: "Bob" } 
Enter fullscreen mode Exit fullscreen mode

You can reassign the name property in this object with no problems.

user.name = "Alice" // will not throw error
Enter fullscreen mode Exit fullscreen mode

But if you reassign a different instance then it will throw an error

user = {name: "Carl"} //throw error
user = "Carl" // throw error
Enter fullscreen mode Exit fullscreen mode
Collapse
 
coderjoe82 profile image
Joseph Padgett • Edited

Yes to this!

I was trying to keep it basic so as not to confuse, because speaking in a newcomer terms, saying "You can't change WHAT type of value const has, if you have an array or object, you can change what's IN the type of value that it has" can be a little mind blowing until you're more comfortable, hah!