A Programmer’s Tour Of Javascript

In the spring of 2014, I took a terrible, terrible web programming course at college. One of the many reasons it was so bad was because of the short shrift it gave to the JavaScript language.

This, unfortunately, seems to be very common among undergraduate courses dealing with any kind of web development. Most of these courses use source material that is geared towards web designers – people whose primary interest is in graphic design or UI design, and who are not themselves computer scientists. Though they are usually 300- or 400-level courses, they never seem to take into account that the students in the class are of the sort that have actually written a compiler, or coded a driver for a network card in assembly language, or who know what P vs. NP means. Instead, the course material is little more than beginning tutorials for people who have never touched a line of C++ in their lives.

This is a tragedy, because JavaScript (and web development in general) is a deep subject. After taking the course (and easily getting an A), I revisited JavaScript to (re-)learn all of the things the class didn’t teach. And now that I know more about different programming languages, I was impressed with how powerful and beautiful JavaScript really is.

So, I’m writing this article to combat the shallow view of the JavaScript language that is fostered among programmers. My intended audience is programmers who know C++, Java, and possibly a functional language like Scheme, and who want to actually learn JavaScript from a programmer’s perspective. It may also be helpful to intermediate JavaScript programmers who want to learn other languages, but will be tripped up by the many differences between JavaScript and other OOP languages.

But it is not meant for web designers. I will not cover HTML or CSS at all. I will mainly talk about core JavaScript, and only those parts that differ from other C-style languages. I will only briefly cover client-side JavaScript, when I talk about the JavaScript environment. There are plenty of other places to learn that stuff. I do assume that people reading this have at least a basic knowledge of HTML, because these days, who doesn’t?

Now, on to JavaScript. To start off, we should know exactly what kind of language JavaScript is.

JavaScript is a dynamic prototyping language. This means it is interpreted, dynamically typed, handles object inheritance using prototypes, and has first-class functions.

It shares none of these things with C++ or Java. In those languages, code is compiled before execution; variables are strongly and statically typed; functions are not first-class citizens; and inheritance is handled by extending classes. This can make JavaScript somewhat foreign to most programmers. On the other hand, JavaScript uses a C-style syntax common to a host of other programming languages (C++, Java, PHP, Perl, etc). It is incredibly easy to pick up if you know any of these other languages; and if you don’t, JavaScript may be a good introduction to them.

This makes JavaScript an ideal candidate for programmers who want to explore high-level subjects (like closures) that would ordinarily require learning a functional programming language like Lisp, Scheme, or Haskell (and their painful syntaxes). JavaScript is also used nearly everywhere, unlike those esoteric functional languages.

Each of these differences requires some explanation, and those explanations lead naturally to JavaScript-specific features and coding patterns. This is not a trivial topic. Even though I broke up the article into multiple pages, it’s still a long read, so be forewarned.

Though everyone uses the term “JavaScript,” the language is specified by Ecma, and the standardized version is technically called ECMAScript. This is the version I will talk about. Some vendors’ impelentations of JavaScript differ from the standard, but I will cover them when the need arises.

After reading this article, you will have a “wide but shallow” understanding of JavaScript, so I also included some book recommendations if you want to learn more.

Addendum: After the article was finished, I showed this to other programmers. I’m incorporating some of their suggestions. Credit and thank-you’s are at the end of the article.

Advertisements

About Karl

I live in the Boston area, and am currently studying for a BS in Computer Science at UMass Boston. I graduated with honors with an AS in Computer Science (Transfer Option) from BHCC, acquiring a certificate in OOP along the way. I also perform experimental electronic music as Karlheinz.
This entry was posted in JavaScript, Programming and tagged . Bookmark the permalink.

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