←back to thread

498 points azhenley | 3 comments | | HN request time: 0.481s | source
1. TheRoque ◴[] No.45772138[source]
I also default to const in javascript. Somehow a "let" variable feels so dirty, but I don't really know why. I guess at this point my experience forged an instinct but I can't even put a theory on it. But it's sometimes necessary and I use it of course.
replies(2): >>45772627 #>>45773213 #
2. catlifeonmars ◴[] No.45772627[source]
In JS, by using const, you are signalling to the reader that they don’t need to look out for a reassignment to understand the code. If you use let, you are saying the opposite.
3. maleldil ◴[] No.45773213[source]
JS's const doesn't go far enough since you can still mutate the object via its methods. In C++, you can only call const methods (which can't mutate the object) on const variables.