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
Login to reply
Replies (2)
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.