
Learning JavaScript - my experience and advice - ibrahimcesar
http://sivers.org/learn-js
======
georgemcbay
"JavaScript: The Good Parts" is a fantastic book, but anyone telling you to
read it if you're coming at JavaScript as your first language is doing you a
horrible disservice.

It is a fantastic book for learning to avoid being bitten by all of the
stupidity in JavaScript if you're used to programming in sane languages, but
it isn't a tutorial or "Learn to Program" book by any stretch of the
imagination.

To be completely honest, I'm a bit horrified people are learning JavaScript as
a first language at all. The language does indeed have its "Good Parts" and it
is incredibly useful because of its ubiquity, but I just wonder how many young
brains are going be hardwired to think some of the design choices (the way
block scoping works/doesn't work, equality, lack of modules, etc, etc) in
current JavaScript versions are normal, when in fact they are very
unfortunate.

~~~
kevincennis
I learned JavaScript first, and I think in many ways I'm actually better off
for it.

Anyone who's serious about JS hears _constantly_ about the problems of lexical
scoping, type coercion, lack of modules, etc. When I moved on to learning PHP
and Python, I largely knew what to expect - and found them both pretty easy
(aside from PHP's standard library being ENORMOUS and impossible to memorize).

On the other hand, I've seen people coming from classic OOP languages really
struggle with things like first class functions and prototypal inheritance.

I don't think the problem is that people are learning JavaScript as a first
language. I think the problem is that a lot of people who write JS don't ever
_really_ learn it.

~~~
PommeDeTerre
I think that you're misinterpreting disgust as "struggle" when it comes to
those people with a more traditional OO background dealing with JavaScript's
prototype-based OO approach.

Languages like C++, Java, C#, Objective-C and Smalltalk have very well-defined
and consistent ways of declaring classes, inheritance relationships,
instantiating objects, using objects, and so forth. With some experience, it
becomes extremely trivial to quickly understand and work with such code, even
when it was written by other developers far away or long ago.

JavaScript is the opposite. Like so much of the rest of the language, its
prototype-based approach is an absolute mess, and this further encourages code
that uses this functionality to be a mess, too.

To see what I mean, look at the examples at:
[https://developer.mozilla.org/en-
US/docs/JavaScript/Guide/Cl...](https://developer.mozilla.org/en-
US/docs/JavaScript/Guide/Closures#Performance_considerations)

Those are three different ways of doing the same thing (and one of them also
has non-obvious resource consumption impacts). Those are a very basic case, as
well, without even any inheritance. This lack of consistency may not seem like
a big deal when it comes to simple examples like that, but it does quickly
become an issue in any code written by more than one or two developers, and
meant to be maintained for years. Some will claim that coding standards will
help here, but they do absolutely no good once integrating code developed
independently of said coding standards.

The numerous problems with JavaScript's approach might be excusable if it
brought any benefit relative to more traditional OO approaches, but it just
doesn't. It takes something that is done quite sensibly in so many other
languages, and ruins it. While somebody who started with JavaScript as his or
her first (and often only) language may not see these problems, it is very
frustrating and disgusting for those coming to JavaScript after years or
decades of experience with other languages.

~~~
greggman
I disagree with your assessment. Arguably your trying to cram non JavaScript
style into JavaScript and then getting upset that it'a not what your used to.

I had a bad opinion of JavaScript at first too coming from a C++ background.
Then I finally stopped trying to make it C++. I never want to go back. Things
that are hard in statc languages are so easy in JavaScript.

My best advice would be to maybe read though one of the more popular libraries
though I don't know which one to recommend. There's a level of elagance there
I rarely see in C++

------
shawndrost
Javascript's secret weapon[1] -- especially for beginning programmers -- is
its dev tools. If you learn JS' debugging toolkit early on, it will accelerate
your learning in general. I recommend Code School's "Discover DevTools" course
[2] for beginning devs, but I'm not aware of a high-quality introduction for
experienced devs.

Shameless plug: I teach at a school for JS devs named Hack Reactor. If
rewriting Underscore as a learning tool sounds like fun, you should apply.
<http://hackreactor.com>

[1] until now. [2] Chapters 3-4. <http://discover-
devtools.codeschool.com/chapters/3>

~~~
minikomi
Indeed. Learning that

    
    
        debugger;
    

will stop the interpreter at any point you like, with console scoped at that
point, has sped up my JS'ing greatly

~~~
grinnick
Wait you can what!?? Holy moly, I've been writing JS for like 3 years now and
I never knew this.

~~~
minikomi
Yep - as long as dev tools are open. Works everywhere, even in eg. underscore
templates, backbone init functions..

~~~
thisone
chrome extension content scripts...

------
philipwalton
JavaScript has three main features that commonly trip up people from other
languages. If you understand these three things, you'll be way ahead of the
curve:

1) What `this` means in a function context [https://developer.mozilla.org/en-
US/docs/JavaScript/Referenc...](https://developer.mozilla.org/en-
US/docs/JavaScript/Reference/Operators/this)

2) The prototype chain and prototypal inheritance
[https://developer.mozilla.org/en-
US/docs/JavaScript/Introduc...](https://developer.mozilla.org/en-
US/docs/JavaScript/Introduction_to_Object-Oriented_JavaScript)

3) Function closures and variable scoping [https://developer.mozilla.org/en-
US/docs/JavaScript/Guide/Cl...](https://developer.mozilla.org/en-
US/docs/JavaScript/Guide/Closures)

------
Alex3917
I definitely agree on JavaScript: The Good Parts -- it's quite possibly the
single most over-rated book I've ever read.

There is literally a Stack Overflow thread devoted to just about every single
code example and paragraph in the book, because no one has any idea what he's
talking about. And even the JavaScript gurus on SO can't figure out what he's
actually trying to say a good percentage of the time.

I'm sure it would be a great book if I were already pretty good at JavaScript,
but as a first book it's just awful. I had much better luck with a HeadFirst
book that covered JavaScript, even though that is a little too dumbed down at
times. I was then able to then go back and have a much better appreciation of
what Crockford was trying to say.

~~~
WickyNilliams
Your second paragraph is nonsense. Any JS expert should be able to understand
every point made in that book, by the very definition of expert.

Your third paragraph is completely sensible however. The Good Parts is
horrible if you're a beginner programmer, and I'd definitely recommend against
it. But if you have a CS degree or years of programming experience, it should
not cause you trouble - it's a great, terse intro to JS that'll get you up and
running in no time.

The worst book to learn from is JavaScript: The Definitive Guide [1]. It's
unnecessarily lengthy (1000+ pages!) and attempting to learn from that has
dissuaded more colleagues from JS than I care to remember.

[1] <http://shop.oreilly.com/product/9780596805531.do>

~~~
Alex3917
<http://stackoverflow.com/search?q=%5Bjavascript%5D+crockford>

------
pyvek
Professional Javascript for Web Developers is really an excellent book. Also,
I would like to mention a blog post [1] by Richard Bowell which was front-
paged here recently who also recommends the same book.

I'm currently learning JavaScript and the thing that sucks is reading about IE
incompatibility/workarounds on almost every other page of the book. Any advice
on how should I handle it? Is it really necessary to keep in mind all those
quirks or can I skip through those material right now and learn what works on
most browsers?

[1] [http://javascriptissexy.com/how-to-learn-javascript-
properly...](http://javascriptissexy.com/how-to-learn-javascript-properly/)

~~~
alxndr
Skip it.

------
mark_l_watson
I tried doing a total immersion in JS recently by coding up small learning
projects for Ember.js, Ember.js + Node.js, Node.js + Express, and some general
experiments while reading "Secrets of the JavaScript Ninja" (I like this book,
BTW).

All that said, I did a 90 minute sprint with Clojurescript tonight, and as
awkward as it may seem to use an intermediate language, the development
process is really nice. Whether I am modifying server side or client side
code, the edit, try it cycle is very quick (a second or so). I have found that
if I make little changes in one cycle, keep a browser JS console open with
logging from client side code, and keep repls open for both the server side
Clojure code and the client side Clojurescript code then I have a good window
into both sides of a web app.

However, Node.js with either something like Express or (if you are brave)
Ember.js is really nice also. I understand why people like Node.js.

------
jurassic
I wish somebody would write a post like this for Ruby. Trying to craft a
personal study plan of the best, most current resources from the large number
of apparently high-quality offerings is difficult for a newcomer to the
language. I'm operating on the assumption that success is mostly path-
independent (just start doing stuff and going through resources, and you'll
learn), but it still feels like a random walk approach to learning sometimes.

I'd also like a list of critical tools for programmers new to the Ruby
langauage. These things don't always get highlighted in beginner resources
because of the need to hand-hold on fundamental concepts for people who've
never programmed. For instance, I wish when I'd learned Python that somebody
would have told me right at the beginning to install ipython, virtualenv, pip,
etc.

Edit: Wow. Thanks, guys, for all the good recommendations.

~~~
marcamillion
I would like to second Eloquent Ruby. Russ Olsen has a magical way of
explaining things in a very simple manner.

I will always read anything he writes. Love his style. Now that I am thinking
about it, I feel like re-reading that book.

The most important thing to remember, when you are learning programming for
the first time, is that the process is very, very long. You make A LOT of
mistakes and it can be INCREDIBLY frustrating. But....once you push through,
and actually validate that you know what you just learned and actually figure
stuff out...I think there are very few highs that rival that rush.

It's weird....but it is EXTREMELY satisfying. I think because the journey is
so hard, that makes the discovery of the solution all the more pleasing.

So, I would say....just prepare your mind that you have a lot of long nights,
and problems that may take you days/weeks/months to "fully grok". Once you get
in that mindset and are prepared to slog through, you will make it and be much
better off for it.

~~~
ivan_ah
@marcamillion Very well said. I have been trying to coin a buzz phrase for
this feeling and the best I came up with was "knowledge buzz."

------
straws
Eloquent Javascript is absolutely the right starting point, I'm glad there's
been a shift from recommending The Good Parts to that one.

It was linked here the other day, but Superhero JS is another great "what is
the path to javascript mastery" lists:

<http://superherojs.com/>

------
nlh
Nobody has commented on the suggestion to aid learning with Spaced Repetition
Software - specifically the Anki open source program.

Anybody try or use this technique? It looks interesting and sounds reasonable
and effective. I took a peek at Anki but have to admit it looks messy (and the
iOS app is $25, which is def. on the high end of the iOS pricing scale). I'd
be curious to hear others' experience in this area...

~~~
zimpenfish
I'm trying to use Anki to learn various things and whilst it does seem to be
working, some of the decks you can download could do with a firm hand on the
layout / design tiller.

e.g. the C one presents the code in an awful centred and line-broken fashion
which completely obliterates the location of significant comments and the
like.

(But I believe the SRS people recommend you make your own decks as part of the
process.)

~~~
subpixel
I highly recommend the code syntax-highlighting extension to Anki:

<https://ankiweb.net/shared/info/491274358>

In a nutshell, pressing the button this extension adds to Anki either pastes
the contents of your clipboard as syntax-highlighted code, or applies syntax-
highlighting to the text you have selected.

This makes code much, much easier to parse, especially when using Anki on a
mobile device.

~~~
zimpenfish
I'm guessing that's not going to do much in the Anki iOS app though.

On the plus side, checking the app to see if such an option exists found a
bunch of options I didn't know about that will make my experience more
pleasant. Ta.

------
tantalor
> you'll love looking at the code to two very popular and powerful JavaScript
> projects: Underscore.js, Backbone.js

Is that a joke? I can't stand reading the source of those two libraries, even
with the pretty two-column documentation. There have got to be better examples
of readable JavaScript.

------
andrus
I'll second the author's recommendation of Effective JavaScript by David
Herman. I've found it very helpful: <http://effectivejs.com/>

~~~
zenocon
I'll third this recommendation. Herman's book is succinct, clear, and well-
written. Although I wouldn't recommend it as your first intro to JS; If you've
already been hacking in JS for a while, and want to take it to the next level,
this _is_ the book to buy.

------
kybernetikos
I've recently made something that I hope to use to teach our new hires (who
will all have programmed before, but probably not in javascript) the ins and
outs.

It's called "New to JS" and is available on github at
<http://caplin.github.com/new2JS> and the source is
<https://github.com/caplin/new2JS>.

Keen to get any feedback / pull requests.

------
akurilin
I've had to learn JS pretty fast just a couple of months ago and from what I
can read I managed to do almost exactly what Derek did, same exact books and
all. Professional JS is indeed fantastic and is highly recommended. Same thing
as far as reading Underscore and Backbone source.

For fun, try implementing something in Backbone. It's certainly one way of
assessing if you're at all proficient in the language.

------
nickporter
It's like people don't understand that JavaScript is a language. The browser
is just giving you a JavaScript API.

------
gavinflud
I read "JavaScript: The Good Parts" after having been using JavaScript for a
couple of months and still found it overwhelming. Douglas Crockford moves
through the topics at a very fast pace.

However, after a few more months of learning the language I went back to the
book and was immediately thankful for how quickly he moved from topic to
topic. I understood the references and was receiving quick tips on what to do
and what to avoid doing with all the different elements that make up the
language.

Also, I agree with the author, Professional JavaScript is the ultimate
JavaScript book in my opinion.

~~~
just2n
TGP is mostly dogma. The title should make that very clear, but unfortunately,
as usual, Crockford is short sighted so the title of his book is misleading,
implying you might learn something about the language by reading it.

A much more appropriate title would've been "JavaScript: Crockford's Best
Practices for Experienced JavaScripters", or "What's Wrong With JavaScript
According to Crockford." Then it's pretty clear what the book is doing, and
doesn't trick readers into thinking it's an introductory or learning book.

A few of Crockford's opinions are fairly widely accepted as good advice, but
much of it is controversial at best, and in practice incorrect or misguided.

If you are considering buying it, just watch the talk instead:
<http://www.youtube.com/watch?v=hQVTIJBZook>.

As for the article: it's mostly sound advice. I will reiterate reading the
source to underscore and backbone. I started recommending this lately to
people after they get comfortable with the language. Many popular patterns and
techniques are used in these code bases and they're very approachable from a
reading perspective. I read both a few months ago to get up to speed on a new
project and I found it quite enjoyable compared to reading the likes of jQuery
or Angular.

------
Millennium
TGP isn't a good book for learning JavaScript the first time, it's true.

The time to read it is when you've been doing this for a while, and it's time
to "unlearn what you have learned" before you can move on to the next level of
expertise. There's a lot of dogma in the book, but that's not bad in the
appropriate context: most people will find something to follow in its pages,
but most people will also find something to question. Both experiences are
valuable, especially for someone preparing to "take the next step," as it
were.

------
fredyr
This is really a good set of resources for learning Javascript. In addition I
want to add the "Learning to love Javascript" presentation by Alex Russell
from Google Code 2011, <http://www.youtube.com/watch?v=seX7jYI96GE> that I
felt really boosted my learning curve (or at the very least kept me passionate
about JS to continue learning as much as I possible could)

------
blacksqr
The world would be a much better place if there were more straightforwardly
helpful posts like this. +1,000,000 internets.

------
reyan
Another book which I really liked is JavaScript Patterns by Stoyan Stefanov.

~~~
pacomerh
Oh yeah, I was gonna write the same thing. This is a great book. I'm actually
going over it again to reafirm.

------
taurath
Thanks a lot for this post. As a relatively new web dev mostly working in
jQuery (I get stuff to work right and be relatively fast, but thats about it),
I've been very curious about where to go next.

------
ryanSrich
I tried a similar approach and kept going back to jQuery first. For some
reason it was learning jQuery that aloud me to really understand Javascript.

I really like the way codeschool teachers their javascript track.

------
pdm55
Wilton "Beginning Javascript" is the essential bits of JS.

Zakas "Prof JS for Web Developers" is comprehensive.

Strom "3D Game Programming for Kids: Create Interactive Worlds with
Javascript" teaches JS by creating games.

------
mtgx
CodeCademy's course is very good, I thought.

------
Helianthus
The attached Learn Backbone.js Completely article is also very good.

Angular has _huge_ obstacles for dev usability when Backbone's source is so
accessible you can use it to help learn js.

~~~
mac1175
This was one of the reasons why Backbone was my first choice compared to the
other "MVC" frameworks. The documentation was simple and I think some the
handling of Views helped you mentally organize your DOM manipulation code
versus having a file riddled with various event bindings with possible
selector conflicts hidden. Right now I am working with AngularJS but the
documentation can be cryptic at times. I didn't have resources like John
Lindquist's site (<http://egghead.io>), I may have suck with BackboneJS. It is
still a great framework but AngularJS, after gaining experience, has some
amazing features.

------
luketych
I think the first spaced-learning algorithm was actually SuperMemo, developed
by Piotr Wozniak. The rest just copy his algorithm.

