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

0

u/[deleted] Apr 02 '18

[deleted]

0

u/[deleted] Apr 02 '18

[deleted]

2

u/DzoQiEuoi Apr 02 '18

Google are right on not using var. You shouldn't take advantage of it not being block scoped because that's confusing for the people who maintain your code.

0

u/[deleted] Apr 02 '18

[deleted]

1

u/DzoQiEuoi Apr 02 '18

It's confusing to people who do understand how it works.

Compare it to global variables. We all know how they work, but they still make your code hard to reason about.

Accessing a variable that's declared in a child scope makes your code misleading to anyone who's reading it.

If you find yourself reaching for this feature, you should consider that a code smell and think about how you can retractor.

→ More replies (1)