3 ms·
Heh. This thread is like an invitation to get downvoted. I'll bite: Using const for all variables in JavaScript is moronic. It's a trend that should have been
by russellbeattie 3y ago
Heh. This thread is like an invitation to get downvoted.
I'll bite: Using const for all variables in JavaScript is moronic. It's a trend that should have been killed with prejudice in the crib. If you want type safety, use another language. Use let for variables and const for actual constants. Words have meanings. The const statement wasn't created so developers could litter their code with it to show how cool they are.
Imagine you're learning JavaScript at young age: "Here are three ways to declare variables - var, let and const - but you should only use the most confusing one that doesn't actually make verbal sense for general use, nor do what you'd think it would do based on its description. Use it anyways. Because reasons."
- p-e-w 3y agoIf the value of your "variable" doesn't change, it's a constant by definition, and a const declaration is appropriate. If it does change, using const will give you an error. Therefore, it's literally impossible to misuse const in a JavaScript program that runs without errors.
- ipaddr 3y agoI'm a fan of let. When you use it all possibilities are still alive when you are declaring. It could stay null or hold an object. The skies the limit. When we use const it limits the variable to whatever wishes I had during declaring but never leaving me room to change my mind. I can't reuse and recycle I always need something new. Pencils have erasers. No one likes liquid paper.
- vunderba 3y agoThis is a highly bizarre take. Do you also object to text types being referred to as strings when they're not actually rope? Because if it's the misleading naming convention, then you have to be consistent in your argument. Constants are a way to give magic numbers a meaningful name, and at the same time guarantee some minimal form of type safety by instructing the compiler/VM/Linter that they're not allowed to be mutated. Also, I don't think I've seen any JavaScript tutorial teach anyone to use var for YEARS, it's really just let and const.