Const is fucking useful
Stop being an asshole.
const
stops you, or anyone else on your fucking team, from reassigning a variable that should remain constant. It doesn’t suggest immutability, and it was never about immutability. There were other additions to the spec that gave us immutability. If you want a variable declaration that is immutable, please try to find a productive way to suggest we need it, and make a reasonable case as to why, instead of calling the work of hundreds of people (present company excluded) fucking useless. You know what was fucking useless? Your post.const myConstant = 'do not change me'
Do you see how it’s useful? If I want to stop a variable from being reassigned, for it to be a constant, read-only value, I now have a way to declare such a thing.
let myConstant = 'change me' // err: nah
var myConstant = 'change me' // err: I said nah
const myConstant = 'sudo change me' // err: fuck off
myConstant = 'change me' // err: butwhy.gif- The linters shouldn’t have to save you from yourself. And no, I don’t have time to talk about TypeScript, either. If you want an immutable object, just program an immutable object???
null
- You’ve seriously confused the idea that
const
not communicating what you think it means with it not communicating anything, well, congratulations that you’ve never entered a gigantic, new-to-me codebase and tried to assign a variable with a name that needed to be constant and gotten anerr
that it was reserved to avoid dangerous side effects. Congratulations that you never worked in a gigantic, new-to-me javascript codebase B.C. (beforeconst
) and experienced a side effect of reassigning a variable by accident that needed to remain constant and breaking everything.
The idea that anyone, let alone a group of intelligent, experienced software engineers would create something that did not set out to solve a problem is absolutely absurd.
The problem is notconst
here. The problem is you, and your attitude. const I_ACTUALLY_GIVE_A_SHIT_IF_THIS_CHANGES = '42'
You’ve decided that usingSNAKE_CASE
communicates a constant better thanconst
does, but like, that’s just your opinion, man. Not everyone is familiar with this form of constant, where as, the termconst
does seem to imply it’s a constant. The difference in your comparison isn’t aboutlet
vsconst
, that’s just poor variable naming (at least it is in this context). It has nothing to do with the function oflet
vsconst
at all. In this case, though, the only variable declaration that protects your program isconst
. Naming collisions happen, sometimes even when you try your best to make your variable names as clear as possible. How do you enforceSNAKE_CASE
for constants?- If you want some good rules to follow, here’s my best attempt:
1. Useconst
when you want a variable to be read-only, and you don’t want it to be reassigned.
2. Uselet
when you plan to reassign or change said variable.
3. Usevar
when you want your variable to be hoisted. (Never is a good option)
4. UseObject.freeze()
when you want to make an object immutable.
5. If you want to change ECMAScript, and you think the community is on board, try doing so constructively, and be open to the fact that you’re, uh, wrong.
My dogs are cute: