How can I prevent myself from learning bad js?

How can I prevent myself from learning bad js?


Hi. Yesterday I had a good time listening Kyle Simpson on JSJabber (episode 220). He explains how JS use is sometime spoiled by trying to make it behave like what it is not. I have very little knowledge of JS, a snippet on the udacity intro nanodegree and skimming Eloquent Javascrip. I just started FCC after the Udacity intro course (which btw is very good)

I wonder how can I avoid bad teaching of JS. Apparently classes are not right in JS, is class a keyword for bad JS maybe?


There’s no yard stick to measure Javascript quality against, unfortunately.
However, you can identify the type of constructs that you are talking about, which try to accommodate programmers coming from other languages, by some common patterns:
Anything that’s just a wrapper around existing functionality and is named like something similar in other languages, is probably unnecessary.

Classes are an example of that, although classes in Javascript are not the same thing as in, e.g. Java or C++. They don’t provide inheritance, but delegation instead, which can cause subtle bugs if one doesn’t know the difference.
Also, the new functional programming trend, for which JS is well suited, does away with OOP altogether and the consensus seems to be that this is probably a good thing.

Another example is types. JS has them, but only under the hood. Forcing JS to do type checking when not needing them is one of its greatest advantages, is clearly a sign of programmers preferring different languages. “So I have to use Javascript, boss? Well fine, but let’s make it behave like Java first.”

I work with a bunch of Java developers and a lot of them, when they try their hand at Javascript, bring in cringe-worthy attempts to feel more at home with the language, by introducing classes, enums and constant type checking clauses, allegedly to “work around some of Javascript’s shortcomings”. But really it’s just them trying to make JS feel more familiar.

The good news is, that JS lets you do all that.
The bad news is, that JS lets you do all that.


I think as a beginner it is good to learn as much as possible from wherever possible.

Even if you learn some bad practices, that’s ok.

The bad practices are bad for a reason, and once you start to feel the pain of some of those bad practices first hand, you are primed to learn the better way and really understand that it is better.

For example, I used write really repetitive, tangled spaghetti code. Nowadays I write mildly repetitive, slightly less tangled spaghetti code…but I was writing lots of confusing nested callbacks and massive single files that handled all every single thing my app had to do. As my projects became bigger I needed to learn how to modularise my code and repeat myself less.

So I reckon, embrace bad code as a beginner. Welcome callback hell with open arms! Learn JS first, then learn how to do it better.

Btw, Kyle Simpson has a great series of free books called You Don’t Know JS, which are available on GitHub - definitely worth digging into once you have a handle on the basics.


Practice does not make perfect. Only perfect practice makes perfect. - Vince Lombardi.

Learn from the best. Find a mentor.
Like what Kyle Simpson says? Ask him to be your mentor.


This is the long and short of it. The only way you can avoid writing bad code is to write bad code. No one takes a few courses, reads a few books, does a few projects, then is suddenly a master.

Write bad code. Make ugly projects. Crash your browser. Then get better.