What are the fundamental things about JavaScript that you wish you’d known when you first started as a developer?

This is a question I have been asked by the amazing Pippa Buchanan from the P2PU school of webcraft. Here is my answer :

I think that JS is a sum of a lot of technologies and that web developers should very early be aware of the differences between them:
1) ECMAScript: That’s the core language JavaScript is based on. That’s “just a programming language”. It defines the JavaScript native types. This include Objects, Arrays and functions
2) The document object inherits form a lot of different interfaces:
* Node which is “just here” for the tree structure (ok, well, a bit more). This interface is common with Elements and contains parentNode, cloneNode…
* Document which contains .createElement, .getElementById. This interface is the one used by the responseXML attribute of XMLHttpRequest. This is common with XML-based documents.
* HTMLDocument. It adds a bunch of HTML-specific things like .body, .links or the .write method (this last one should be avoided, but that’s another story)
* HTML5 redefines the HTMLDocument interface and add for instance .getElementsByClassName()
3) Events
Besides that, the event programming paradigm is not easy to understand. Unlike “C programming” where you have a “main” function and a “return” at the end, JavaScript isn’t continuously executed. There is a bit of execution at the beginning for initialization purposes and after that it’s all user (click/keypress) or network (XMLHttpRequest events) or clock (settimeout) driven which could be all summarized as “events” (even if the clock “events” aren’t DOM events).
The DOM event mechanism is well explained in one picture.

One thought on “What are the fundamental things about JavaScript that you wish you’d known when you first started as a developer?

  1. I’d suggest to also be aware of the OOP ways of coding JS from the start. It enhances readability and enables design patterns.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s