How to start with JavaScript Programming

For Short

To have an environment running JavaScript code, you should preferably install Mozilla Firefox. Then you just need to hit Cmmd + Opt + k or Ctlr + Shift + k.

You are ready to start programming in JavaScript.

Here is some details you should know before start typing:

JavaScript…

  1. has C-like syntax.
  2. has Functional features, like First-Class and High-Order Functions. But not immutable state.
  3. has Object-oriented features. Everything is an Object and it’s Prototype-based rather Class-based, as the most well-known OOP languages.
  4. is dynamically typed and uses duck typing.
  5. uses call-by-sharing as evaluation strategy, as well as Ruby and Python.
  6. is single threaded. You’re basically going to handle async computations using events or callbacks (or promises).
  7. has a pretty good package manager called npm. You can use it by installing Node.js or io.js.
  8. has an API to manipulate the DOM, which is slow.

Good luck !

Not-so-short version

If you’ve reached at this point, you’d want someone to show you a safe path. Here it is.

Warning This guide is obviously biased by my experience and background, even though you should check out the resources by any means.

Instalation

Node.js (or io.js) instalation is pretty straightforward. You can download it from their website or grab it from repositories out there. Or using brew install nodejs, if you’re a Mac OS X user.

As many other modern programming language, you should be able to use its package manager as well after instalation. It’s called npm and has a bunch of nice features and a lot of modules. You should definitely use it.

First Steps

Initially, you should understand the language itself and there’s 2 good (and free) resources for that:

These books are specially good if you don’t have any background in (imperative) programming or low-to-none experience at programming.

Once you’ve done learning JavaScript basics, you can dive into Effective JavaScript, by David Herman. Herman is one of the authors of the language, it’s a pretty good idea to check out what he has to say.

Mastering

To master JavaScript, I believe you must successfully get along with 3 specific topics:

  1. Functional Programming
  2. Prototype-based Object-Oriented Programming
  3. Async/Concurrent Programming

Diferently from Eric Elliot, who believes JavaScript has 2 pillars (the first two I’ve listed), I think it’s important to have a good understanding on how to handle Async computations and to correct synchronize them. I’ve seen a lot of good programmers failing on handling async computations and triggering race conditions, etc. It’s a subject you really should put some efforts on.

Functional Programming

I don’t think you should dive into other programming languages (as I did) to understand some Functional Programming Principles and apply them into your everyday code in JavaScript.

The minimum knowledge:

  • What is and how to get along First-Class and High-Order Functions;
  • How to proper work with map, filter and reduce;
  • How to build curry-ed functions and use parcial application;
  • How to compose functions and pipeline function calls.

There’s 2 books that may help you in your journey:

Anyhow, if you think you have enough time and motivation to learn Functional Programming from the ground up, you should drop the previous ones in favor of:

The best part is that SICP and HtDP are available for free for online reading, as well as JavaScript Allongé.

Prototype-based Object-Oriented Programming

That’s a tough subject for the most experienced programmers out there, specially because we’re all too much used to Class-based OOP. In addition, most of the programmers thinks classes are a must-have concept for OO programs. But it’s not, like JavaScript and some others have proved us.

Prototype-based style is expressive in comparison to Class-based style, once you can write the second in terms of the first (the reverse is not possible). The sad part is that we don’t have too much resources to really learn the Prototype-based style. Instead, there’s a plenty of content teaching you how to magically transform it into Class-based and moving on.

The minimum knowledge:

  • How to work with Prototypes
  • How to properly use Object.create, Object.defineProperty, etc
  • Understand correctly the Prototype chain

I think you should read Elliot’s chapter about Objects and Object-Oriented Programming from his book and his blogpost about it. Sorella also wrote a good article on JavaScript OOP.

Async/Concurrent Programming

It’s not that common a environment running async by default. However, it is JavaScript’s env scenario. Most of the time, you’d need to handle async computations and sync them. Async programming is not optional or avoidable here.

The minimum knowledge:

  • Correctly understand the Event Loop and how to manage native and artificial events
  • Master promises

For this, there’s an interesting book called Async JavaScript, by Trevor Burnham, that covers the basics of the single threaded nature of JavaScript engines, events, callbacks and promises. Also, there’s a good article and talk about Event Loop you can follow.

Nevertheless, events and promises aren’t all you got. You should be aware of async/await, which is going to be available on JavaScript engines soonish, but also CSP, FRP and maybe Transducers. How to correctly do async computations in JavaScript (and in many other languages) is still under discussion and you’re a probably going back to this subject many times during your work life.

Closing Thoughts

Of course there’s a lot more of JavaScript knowledge you should present for building application. I think most of them you can derive while you’re practicing or working, once you’ve mastered the above-mentionend topics. However, if you’d like to have a guided walk-through, I’d suggest you to have a look into Human JavaScript book, by Henrik Joreteg. It covers modern JavaScript development of client-side applications, by going through the fundamentals of models, views, templates and routing.

I don’t think you should put too much efforts on learning a library or a framework. They will be replaced soon or later. You should always target towards a broader undestanding of the concepts and how to apply them in your everyday work.

Wanna read more?