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.

15

u/ghostfacedcoder Apr 01 '18

Why not? I can accidentally assign to a variable inside a function can't I? Const vars prevent that from happening, and cost you nothing (except having to type one extra character vs. let).

-2

u/lordxeon Apr 01 '18

Function level variables

I don't think variables declared inside a function should be declared with const. Any global, or global equivalent are fine being const if necessary.

And, they do cost you something because unless you're running the ES6 code by default, it's being converted back into vars by babel anyway.

→ More replies (1)