r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

141

u/inabahare May 28 '19

Using const and let

30

u/rook218 May 28 '19

Learning what linting is has saved me so much time and energy with hammering in simple syntax rules like that.

Another thing I'd say is to learn DOM manipulation first. I got stuck for a month or two on using JS to solve algorithmic problems in online courses like free code camp, but after I had a solid grasp on JS I still had no freaking idea how to actually use it. Starting with the basics of selecting an element and adding a listener would have been a huge boon to my progress.

10

u/yeah666 May 28 '19

I was in the same boat as you. Wes Bos' Javascript 30 helped me get over that hump.

8

u/ScientificBeastMode strongly typed comments May 28 '19

Yeah that’s one of the huge advantages of JavaScript. The visual feedback loop is so much faster with JavaScript than with a lot of other languages, simply because it works in the browser. And building UI with it is a breeze in comparison to other things.

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)

→ More replies (15)

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.

→ More replies (1)

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

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

8

u/Murdathon3000 May 28 '19

I don't know, if you're a beginner that just started learning JS in the last couple of years, virtually every resource (at least in my experience) hammers down let and const pretty much right away, or at least very early on.

9

u/inabahare May 28 '19

Yet if you pay attention to the beginner questions asked here and other places, a lot of them use var instead of const or let. That is mostly because a lot of schools/universities/whatever aren't that good at keeping up

3

u/Murdathon3000 May 28 '19

Fair point, that's absolutely true come to think of it.

→ More replies (2)
→ More replies (3)