Hacker News new | ask | show | jobs
by MsMowz 1920 days ago
>Basically all uses of const in JavaScript are pointless. I have asked many times for someone to show me an example of a bug that shipped that would have been prevented by const as it exists in JS. I'm still waiting.

You have it backward; there's almost never a need to use let in JavaScript, as most variables should never be reassigned.

I've seen bugs pop up many times in client-side development where, for whatever reason, a variable is reassigned in a way that's difficult to predict. By defaulting to const unless reassignment is necessary, you're essentially putting documentation into the actual code and you can prevent logic errors by forcing runtime errors during development.

1 comments

> as most variables should never be reassigned.

Why not? Reassigning globals can lead to bugs, sure. But when does reassigning a local lead to bugs?

> By defaulting to const unless reassignment is necessary, you're essentially putting documentation into the actual code

No, by defaulting to const, you're removing documentation. "Does this variable need to be kept safe from reassignment? Is it ever used again after this point in the code? Or is the developer just blindly using const for no reason?" Gotta read the code to figure it out because now const is just meaningless noise.