5 ms·
I resisted const for like 10 minutes. You get used to it really quickly and then when you see a 'let' in your code you just know something is happening with tha
by pmoleri 10y ago
I resisted const for like 10 minutes. You get used to it really quickly and then when you see a 'let' in your code you just know something is happening with that variable afterwards.
When I have to go back to programming in a language without const declarations it feels bad.
- JoeAltmaier 10y agoI know I should use const. I lazily leave it until the end then try to shoe-horn it in. Then it ripples through the code until I give up. Then I hate myself.
- dsp1234 10y agoI've started to use const for every variable, then if I get an linting error about modifying a const, I switch it to let. It took about two weeks to train my hands/brain to type const before let/var.
- rkwz 10y agoI use https://www.npmjs.com/package/eslint-plugin-const-immutable https://www.npmjs.com/package/eslint-plugin-const-immutable for linting const usage. It even detects object props mutation!
- pauljaworski 10y agoThis is what makes Eslint so great. If you extend Airbnb's (or write your own very strict) config, it will really enforce best practices for things like this. I think running eslint --fix will even change your "let"s to "const"s where appropriate, but don't quote me on that.
- btdiehr 10y ago--fix is a godsend.
- rkwz 10y ago>I think running eslint --fix will even change your "let"s to "const"s where appropriate, but don't quote me on that. Yep, this is the relevant rule - http://eslint.org/docs/rules/no-var http://eslint.org/docs/rules/no-var Though it just replaces all var with let. I expected it to intelligently use either const or let depending on how the variable is used ¯\_(ツ)_/¯
- Zirro 10y agoYou're looking for: http://eslint.org/docs/rules/prefer-const http://eslint.org/docs/rules/prefer-const It does exactly what you describe :)