by russellbeattie · 3y ago · 0 comments
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."
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.