r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

Show parent comments

0

u/[deleted] May 28 '19

[deleted]

33

u/[deleted] May 28 '19

VSCode masterrace but WebStorm is right here. (Modern) JS shouldn't use var when not explicitly needed.

8

u/g0liadkin May 28 '19

I'm curious, would you say there is a situation when it's actually needed to use var?

10

u/Careerier May 28 '19

When you can't use a compiler like Babel and you have to support older browsers that don't know what `let` and `const` mean.

5

u/[deleted] May 28 '19

I imagine it can be more convinent sometimes to have a function-scoped variable. But even then we're probably talking about quickly hacking things together.

Out of the blue I cannot give you a production example of "a var variable would be better here"

8

u/turntopage294 May 28 '19

Out of the blue I cannot give you a production example of "a var variable would be better here"

I couldn't even give you a textbook example...

→ More replies (12)

26

u/[deleted] May 28 '19 edited May 28 '19

It's not an IDE that errors anything, it's linters. And VSCode comes with ESLint which gives a warning for var usage with default rules, so idk what you're talking about.

11

u/BehindTheMath May 28 '19

Webstorm has some built-in linting even without ESLint.

3

u/[deleted] May 28 '19

Which linter?

14

u/BehindTheMath May 28 '19

I don't think it has a name. It's just part of the IDE. They call it Inspections.

6

u/Max_Stern May 28 '19

It's part of IDE core.

5

u/ingrown_hair May 28 '19

What’s a good lint rule set for beginners? I’ve been writing JS for 6 years. I recently started with the AirBnB set and it’s draining my will to live.

18

u/fucking_passwords May 28 '19

Gotta shake that attitude, if adjusting how you code makes you really upset, you are setting yourself to have a bad time in this industry.

I use airbnb core, but with a few rules adjusted to my liking. It took a while to get used to, and some of my teammates complained, but you know what, now our PRs all look consistent. I don’t care how much people complain, it’s worth it

5

u/verymickey May 28 '19

Where do you adjust the rules? (Non coder here just want to pass this along)

3

u/HansonWK May 28 '19

Do you know anywhere that has good explanations for why some of the rules exist in the airbnb style guide? The team I'm on is going to start using a style guide soon as we have expanded the team, and looking through the airbnb styleguide, about half of the rules I don't really understand what they are for. I don't want to use AirBnB's if we are going to end up ignoring half the rules, and go for something less strict instead at least to begin with.

3

u/acemarke May 28 '19

Yeah, I used to recommend Airbnb's style guide, but it's gotten way too over-opinionated in the last couple years (especially on the React side).

I'd suggest using eslint-config-react-app as a baseline, as it only warns about things that are actually likely to cause issues.

2

u/fucking_passwords May 28 '19

The official repo explains all the rules. At my company we ended up making our own config that extends the airbnb one, and I’m generally fine with people ignoring certain very opinionated rules in their projects if they want.

No regrets. Our projects are much more consistent, and nobody has really complained

3

u/HansonWK May 28 '19

It really doesnt though. It has one line for what the rules does without why it's needed, what its there to prevent. It seems like overkill for smaller teams where people mostly work on their own code, but still want it to match.

2

u/fucking_passwords May 28 '19

https://i.imgur.com/yv8LHg5.png

Looks like there is a "Why" statement for many rules/examples. The ones that lack a "Why" seem to mostly just be "because consistency".

I gradually learned what each rule does, by reading their docs and googling the rule if I still didn't understand it. Might not be ideal, but honestly I learned a ton by doing this.

I'm conflicted. I've worked alone, on small teams, and large teams. I now lead a medium sized team and oversee the projects of other teams. I've used airbnb to varying degrees, also standardjs. Now I don't like working without it. It took some getting used to, to feel like the linter wasn't getting in the way, but now I would never go back, even in personal projects.

At some point you have to compromise. Not everybody is going to love every single rule, especially if you use Airbnb out of the box.

People on your team may only work on their own projects, but what happens when someone quits? Now somebody else has to take over that project, and the closer it is to a common linting config, the easier that process is going to be.

→ More replies (2)
→ More replies (3)
→ More replies (1)
→ More replies (4)

6

u/[deleted] May 28 '19

I have been using AirBnb for a couple of years now and I love it. It's strict and rules make sense.

2

u/micppp May 28 '19

This. I’ve turned only one or two rules off in legacy projects but other than that I think it’s near perfect.

3

u/Choltzklotz May 28 '19

protip: edit the config to only warn (or even disable) some stuff while writing (whitespace stuff mostly), and fix all of them at once before deployment. saved me a ton of nerves

2

u/ScientificBeastMode strongly typed comments May 28 '19

This is exactly what I do. I find it infuriating when I have an extra compile step in development just to fix some white space errors.

→ More replies (2)