`const` in javascript was a mistake (like most things in javascript)
Login to reply
Replies (23)
let it go
and use rust? With the machine's help I am finally giving that a go
Typescript, but Rust is even better
Typescript still has the let/const dichotomy. I held on for a long time, but adopted ts in 2023
"Glad to hear you’ve embraced TypeScript! It’s fascinating how languages evolve over time. Whether it’s let/const or something else, every tool has its quirks. Here’s to your coding journey in 2023! 🚀"
Avoided it like the plague

why?
What's the problem with `const`?
The necessity to go back and forth between `let` and `const` depending on whether a variable is reassigned isn't worth the mental overhead conserved by knowing that a variable isn't reassigned provided by `const`
😂
I (and the LLMs) spend way more time switching between const and let because the linter tells us to than relying on something not being reassigned because it's declared with const. If you need const, your scopes are too big.
Just use Rust everywhere... If LLMs are so good, what is the purpose of JavaScript at this point?
I've already stubbed out a re-write of welshman in rust. I don't know how it'll turn out, but I'm definitely interested in the idea
so you want const to be used only for global constant, for example const SecondsInDay. Correct?
Just do `let SECONDS_IN_DAY` and call it good
Yeah const everything. mutable is a smell for me. If I have to use a mutable variable I'm probably doing something hacky.
Sure, but the language's conventions are very reliant on reassignment. And const doesn't prevent mutation anyway. I say this as someone whose favorite language is clojure
True, but it allows for an immutable pattern in an designed mutable language (which is an argument against const existing at all). const does prevent assignment, just not mutation of the object. Same could be said for C (also my favorite language). Const just changes the compiler enforced memory location protection.
I'm trying to make sense of this argument though. I suppose, coming from strongly typed/functional languages into JS, I developed my own idiomatic patterns to sidestep the designed mutability of the language.
I would also agree in theory that const as a concept in JS shouldn't exist if it was true to the way it's taught.
To your point https://git.vaughnnugent.com/cgit/vnuge/plugins-essentials.git/tree/lib/vnlib.browser/src/default/session/index.ts#n289
Usually I would gate this functionality behind a branch to avoid reassigning a variable. It's very rare for me to use a mutable variable except in a very controlled scope. In some parts of this library I've wrapped with getters and setters.
Encapsulation assumes developers are dumb and will shoot themselves in the foot. They are, and they will, but I prefer my code to have affordances for me to do weird things. But a big part of that is the difference between being a one-man team with comprehensive knowledge of the codebase and being on a larger team with shared institutional knowledge.
My complaint is less about const, which is a good idea, than about linters wasting my time by making me switch back and forth. The number of times const has saved me doesn't compensate for the busy work of pleasing the linter.
I use the Deno linter. While I find it beneficial in my code to differentiate const and let, it can be turned off fairly easily.


Deno
prefer-const
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
Const is for compiled languages, not scripted languages. The closest concept to a const in a scripted language is an enum.