JavaScript (or any other) as a First Language

A few weeks ago John Resig announced that Khan Academy will most likely be using JavaScript as the language of choice in Computer Science – prompting the discussion on the viability of using JavaScript as a first language.

If you don’t know what Khan Academy is – it’s a not-for-profit organization which tries to provide free education to everyone. If you don’t know who John Resig is (seriously?) – he’s the creator of jQuery – the popular JavaScript plugin.

At first I thought it’s a pretty good idea – after all, who is going to disagree with John Resig – but after some consideration I think there might be some better choices for a first language.

The ideal First Language

It might be easier to simply consider what the perfect first language would look like rather than simply going through the list and picking a language. In my opinion, the perfect first language should be

  • Very visual. It should be possible for a new programmer to write a few lines of code (preferably only one or two) and immediately see the results. Pretty much every language has some advanced visual libraries, but these can be very confusing for someone new to programming.
  • Simple. This is obvious. While I have seen discussions on StackOverflow that seem to advocate that you simply ‘stick with C++’ I don’t think this is the correct approach. It seems to me there is a phase where a new programmer first needs to learn how to think like a programmer, before making the jump to any sort of programming technique. That’s my opinion anyways. If my first programming class was in C++ I might not have chosen this career – I just don’t see how it would have been much fun. The syntax also needs to be straightforward – we can sacrifice functionality for simplicity – in fact, it’s probably a good idea. ‘Simple’ in my opinion also refers to areas such as the IDE and project structure – I can’t imagine it would be very easy for a new programmer to understand the project structures in Visual Studio or Eclipse.
  • Easy to debug. To a certain extent this ties into the first point – if you can see what’s going wrong it’s much easier to figure out where the code is going wrong. If your application simply spits out a single number without any explanation you’ll likely need some more advanced debugging tools and techniques, which would probably confuse a new programmer.
  • Consistent. This is maybe a bit more difficult to explain, but it comes down to the element of least surprise (which is so often mentioned in Ruby) – different areas of the language should perform consistently. The greater the lack of ‘special cases’, the better.

Now that we have some idea of what we’re looking for, it might be a bit easier to evaluate the languages available to us on this criteria. It’s clear (in my mind) that most of the popular languages fail on one or more of the criteria I outlined above. For example, C++ probably fails on the first 3 points (it’s not very visual, it’s not simple, it’s not easy to debug) while Ruby fails on the first point and possibly the second one (it’s not very visual). This probably implies that Ruby is a better ‘first’ language than C++, while neither of them would appear to be a great choice.

How does JavaScript stack up?

How does JavaScript stack up on the criteria I outlined? Let’s consider each in turn.

Very visual. This is probably what I like about the idea of using JavaScript as a first language – the results are very visual. It’s easy to imagine that your first few programming assignments would involve moving elements around on a page. Anyone can go right ahead, write a few lines of code and see the results right away.

Simple. This is a tricky point to evaluate – JavaScript can be both very simple and very complex. For example, I like the idea that you can learn JavaScript without learning Object-Orientated programming – while you definitely want to learn those concepts at some point, starting out with them might be a bit too much. However, I don’t like the idea that it’s often possible to do everything in JavaScript in 50 different ways (iterating an array, anyone?). The real complexity within this context, however, is that you can’t learn JavaScript on it’s own. You’ll need to learn a bit of HTML, a bit of CSS and then you can start to learn some JavaScript. That’s all a bit overwhelming for someone who is completely new to programming.

Easy to debug. Again, JavaScript doesn’t really pass or fail this test outright. It’s relatively easy to debug some of the issues (using either alert statements or a debugger), but I have often struggled to debug some JavaScript issues which would tend to indicate the opposite.

Consistent. I would say JavaScript fails this test – apart from some small idiosyncrasies in the language there is the real annoyance of testing against different browsers.

Based on the criteria I outlined I would probably say that JavaScript doesn’t do too well. We could probably go through all popular languages and evaluate them based on this criteria, but since the evaluation and the criteria I thought up is both very subjective it won’t really tell us anything.

What are some alternatives?

As I mentioned in my ‘about me’ page I started off programming in Logo. While most would probably dismiss this as way too simple, I like the idea of having a simple language which still allows the student to test the limits of what’s possible. For example, one of my first projects was to write Tic-Tac-Toe – you could either write a very simple little interface or you could write something advanced with better graphics, mouse control and AI. And you can still start off and draw something on the screen with one or two lines of code.

A language like Logo passes all the criteria I outlined above, but it could simply be because I had a language like this in mind when I drew up the criteria.

There probably is a lot to be said for starting out programming in a language which will still be valuable later on in your career – languages like C, C++, Ruby, Java, JavaScript, Python all score well in this area. The criteria for choosing a first language also heavily depends on your background – for someone who is still at school a simpler language is probably a better idea while someone who is a science major at University would probably enjoy something with a bit more firepower.


I guess if I had to start programming today I would probably choose to do so in Ruby. While it’s not a very visual language it’s still reasonably simple and very consistent – you can also start off by writing something in one or two lines of code. In any case, if I had to start off today I probably wouldn’t fare all that well if I needed to learn HTML, CSS and JavaScript all at the same time. It will be interesting to see what the final choice of language is at Khan Academy and how it’s accepted.

I think this is a really interesting topic – what was your first programming language? Don’t be shy – leave a comment below. I would actually love to put up a poll, but the alternatives are probably so wide I wouldn’t know what to put as the different options!

Happy coding.