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.

5

u/[deleted] Apr 01 '18

It's a phase. At one point in Java a sub-group of FP aficionados were obsessed declaring every local variable final, regardless of practical utility. Now people are taking a few steps back and applying more common sense. Java 8+ even permits capture of variables that are effectively final, without them being explicitly declared final.

1

u/slikts Apr 02 '18

The analogy to the Java situation is not very apt, since there's no impracticality in avoiding var; code that only uses const or let is more consistent than code that also uses var, and using const by default makes code more readable, since the reader doesn't have to consider possible reassignment.

→ More replies (2)