Appendix C. Hitchhiker’s Guide to JavaScript and the DOM


If you have used a language from the C, C++, C#, and Java family, then the JavaScript syntax will feel immediately familiar. And if you have used any dynamically typed language (like Perl, Python, or Ruby) before, then most of JavaScript’s semantics will appear familiar as well.

That being said, JavaScript holds more than its fair share of surprises. Following is a list of “gotchas”—features of the JavaScript language that you are likely to encounter in practice (when working with D3 in particular) that might not become obvious just by reading the code or skimming the reference. (This section does not pretend to be a comprehensive introduction to the JavaScript language; see the pointers at the end of this appendix for some recommendations.)

Hosted language

JavaScript was originally designed to run in a hosted environment, specifically, in the browser. This means that many services usually provided by the operating system are unavailable; in particular, the filesystem is inaccessible (and so is the standard output channel). The network, on the other hand, can be reached. The purpose of the Node.js project is to provide a standalone JavaScript runtime environment that can run outside of a hosted environment (“on the server,” as opposed to in the browser).

The host environment provides a number of services. Of particular practical importance is the global console object, which gives the programmer access to the ...

Get D3 for the Impatient now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.