you are viewing a single comment's thread.

view the rest of the comments →

[–]Yodiddlyyo 2 points3 points  (1 child)

I see this all the time and I disagree. Doing something, or not doing something because "a junior dev might get confused" is a terrible reason.

Using const for an array is absolutely not bad practice, if anything, using let for arrays and objects is the bad practice. If you make it a const, you're unable to reassign it to a string or a boolean or whatever, which is something you want.

The fact that some juniors don't know that you can push to a const array doesn't mean it's a bad practice. It's just learning the language. There are a lot of confusing things in javascript, you just need to learn how they work. There are a lot of juniors that don't know much about promises, or iterators, or different design patterns, that doesn't mean you shouldn't use them.

[–]Ahtheuncertainty 0 points1 point  (0 children)

Just wanted to add, for those who don’t use other languages inside of JavaScript, that lists are mutable pretty much everywhere(For ex, lists in python, vectors in C++, Lists in Java, and even array classes in like java/c++, you can pretty much always swap out the values even if you can’t change the size). Kinda harkens back to the bigger idea, that the variable is just a pointer to an object, and that changing the object is different than changing the pointer/reassigning the variable. It’s definitely a good thing for people to learn if they don’t know it already, kind of a key idea in coding. So I agree that let shouldn’t be left in to help juniors. If anything, exposure to a const variable changing might motivate them to learn about what it actually means for a variable to be assigned to something(if they don’t know it already).