r/javascript • • Apr 01 '18

Google publishes a JavaScript style guide. Here are some key lessons.

https://medium.freecodecamp.org/google-publishes-a-javascript-style-guide-here-are-some-key-lessons-1810b8ad050b
714 Upvotes

317 comments sorted by

View all comments

-14

u/lordxeon Apr 01 '18

Use const by default

I will get downvoted for this, but (like everything) JavaScript developers take a good idea, and destroy it. Function level variables should not be a const. Const variables should be those that never change during the run-time of the application.

4

u/inu-no-policemen Apr 01 '18

Currently it's backasswards. You write your code with let, then your editor tells you that you never reassign anything to it, and provides a quick-fix to change it to const. Or you use const and then there's a quick-fix to change it to let.

It would make more sense if the machine would simply tell you via highlighting if you're reassigning something elsewhere or not. Not only wouldn't you have do anything to get that, you'd even see this information whenever and wherever the variable is used.

0

u/slikts Apr 02 '18

Code isn't always read in an editor that can analyze it, and making it explicit that reassignment is not intended also helps avoid doing it by mistake.