I'm a Systems Reliability and DevOps engineer for Netdata Inc. When not working, I enjoy studying linguistics and history, playing video games, and cooking all kinds of international cuisine.
Other than the readability aspect (which is indeed big), there are a few other bnefits to using const that many people don't think about:
It tells the JS engine that the reference won't change. This sounds useless, but it has the potential to allow for some optimizations that would not otherwise be possible. I'm not sure whether any of the big JS implementations actually take advantage of this or not, but it's still worth considering.
Some IDE's, as well as some code checking tools, can be configured to complain if they see an indentifier declared with const on the left side of an assignment expression, even if the assignment would be to a property of the referenced object.
Honestly, if I know for certain that something shouldn't change, I use const, period. Yes, it can lead to confusion, but that confusion is usually less significant than properly annotating that something shouldn't change.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Other than the readability aspect (which is indeed big), there are a few other bnefits to using
const
that many people don't think about:const
on the left side of an assignment expression, even if the assignment would be to a property of the referenced object.Honestly, if I know for certain that something shouldn't change, I use const, period. Yes, it can lead to confusion, but that confusion is usually less significant than properly annotating that something shouldn't change.