DEV Community

Discussion on: const over let unless I'm forced to

Collapse
 
andyrewlee profile image
Andrew Lee • Edited

Thanks for pointing that out. I just made an edit to the post to address this.

I still would recommend using const for objects and arrays since mutating an existing array or object. This way I can stick with this rule. When I create a new object after mutating it (common in React), JavaScript will force me to use a variable.

const c = { b: 1 };
c = {...c, b: 42};
Enter fullscreen mode Exit fullscreen mode

What's most important is for the team members to be on the same page and use linters if possible to codify the understanding.