Home > Programming > Why JavaScript is AWESOME

Why JavaScript is AWESOME

JavaScript is an awesome language. Now, a few years ago, you’d be marked out as a weirdo for saying something like that. I think there’d probably be some kind of witch-burning ceremony or something, because JavaScript was this stupid language which had stupid syntax and stupid scope and was used to do stupid things by stupid people and just led to awful spaghetti code and killed kittens.

These days people are more understanding, and more and more are coming out of the JavaScript closet. It’s starting to become cool. And I don’t mean cool as in “look at this cool bouncing text” (only works in Internet Explorer 4+ and Netscape 3+); I mean cool as in “hey, check out that cool guy over there writing JavaScript, look how cool he is!”. These days John Resig is a ninja and Douglas Crockford is Chuck Norris.

Douglas Crockford with guns

If Crockford builds JSON without quotes around the labels, it's still valid JSON. - TheReincarnator

Seriously though, what’s so great about JavaScript?

Functions or lambdas

A rose by any other name would smell as sweet, and JavaScript’s functions are sweet like chocolate. I tried to explain to a friend recently just what was so great about JavaScript. What I decided was that it was the functions. JavaScript’s functions can act like lambdas, functions and methods. They can be used to create modules, namespaces, classes and objects. A language like Ruby is a toolbox with some really neat little tools that do their job really nicely. JavaScript is a leather sheath with a really really sharp knife inside. That knife can cut anything, and with it you can do anything. You can kill a bear. You can catch fish. You can whittle a piece of wood into a pony. It’s even a toothpick.

So what makes JavaScript functions so great? It’s two things I think: first-class citizenship and closures.

Functions as first-class citizens

Functions are people too you know? Well, no they’re not actually, but they are objects. They can be passed around like any other object. They can be assigned to variables, passed as arguments, and even returned. And because you can write function literals in JavaScript, you can return a function without even naming it:

function outer() {
    return function () {
        alert("I'm in ur function, accessin' ur local variablez");

This kind of thing is really powerful. I’m not going to try to give any clever examples because it’s the kind of thing you only truly get once you’ve done it yourself and suddenly the whole universe opens up in your mind.


A closure is a funny thing to get your head around. If you’re used to a static language, then it just won’t make sense. Really it’s another one of those things that you have to do until you transcend, but I’m going to have a go explaining it.

Closures are intimately related to first-class functions. One of the things you can do with a function in JavaScript is define it within another function. You can nest functions as deep as you like. Here’s an example of a nested function:

function outer() {
    var name = 'Bob';
    function inner() {

So, in this example, when outer is called, it defines name and inner as a local variable and function, respectively (i.e. they are not visible outside of outer). Then inner is called, which alerts name (‘Bob’). That’s not very exciting though – all it shows is that a function can access variables defined in an enclosing scope. But look what happens here:

function outer() {
    var name = 'Dave';
    function inner() {
    return inner;
var something = outer();

Now outer is called, and it defines name and inner like in the previous example. This time, however, inner is returned (alternatively, I could’ve just returned it as a function literal like earlier). When outer is called, its return value is assigned to something. something is now the same function as inner. But what happens when we call something? outer has returned, so when something tries to access it it’ll probably segfault or something. Well, no, it won’t. That’s where the magic happens. When inner was returned, it somehow magically “closed over” its containing scope, essentially keeping it all available even after outer returned. You can do this with arguments as well:

function outer(arg) {
    return function () {

This time the returned function has access to the argument of the outer function. That last crazy line there with all the parentheses isn’t Lisp, it’s JavaScript, believe it or not (Lisp parentheses are nested, in case you ever need to tell the difference). outer is getting called with an argument of 5, and then the return value of that call is called itself.

These two things, first-class functions and closures, are what make JavaScript functions so powerful and flexible. Again, this power needs to be felt to be believed, and the only way to feel it is to write it.

Douglas Crockford

Another thing that’s great about JavaScript is Douglas Crockford. He not only wrote the best book on JavaScript – he’s also given the best talks on the language.

Dynamic typing

I’m a big fan of dynamic typing. It adds so much flexibility, agility and speed to programming. It also makes programming much more fun. I’ve written a few posts on the subject so no need to go into more detail here.

Conceptual purity

If I went back ten years and told anyone (myself included) that one of the great things about JavaScript was its conceptual purity, I’d be laughed out of my time machine. But it’s true, there’s something really pure about the language. What can be achieved with such simple language constructs is amazing. There are just objects and arrays (and arrays are just specialised objects). There are literals for objects and arrays. There are functions, and loops. And that’s pretty much it. No classes, no modules, no iterators, no generators, no templates or generics, no macros. None of these things because they just aren’t necessary when functions are allowed to be free as nature intended. You’d think that it would feel limiting not having these features, but it’s actually liberating. It feels clean, and pure. But powerful. Like a polar bear.

Why JavaScript isn’t awesome

There are a few small things that I don’t like about JavaScript (and are generally considered a Bad ThingTM).

Implied globals

If you don’t declare a variable as local with var, you’re making it global. I don’t need to go into why global variables are a bad thing, because everyone else has.

Semicolon insertion

There was a programme on TV once and they showed all these x-rays with weird things in like toy cars and bottles and stuff, and … oh yeah, semicolon insertion. That’s where the JavaScript interpreter makes it easier for non-programmers to write JavaScript that works and makes it harder for programmers to write JavaScript that’s correct. Silly. Here’s what happens:

return {
    javascript : "fantastic"
}; //This will return an object with a single property

//the interpreter sees this as an empty return statement so inserts a semicolon:
return //this line is interpreted as "return;" - with a semicolon
    javascript : "fantastic"
}; //this is just an empty block now.

But I love it really

It’s easy to mitigate those two things with decent coding practices. Basically, always use var, always use semicolons where necessary, and always put the opening brace at the end of the previous line, not at the beginning of the next. Finally, put anything you write through JSLint. It’s like a compiler, without the necessity.

Further reading

JavaScript: The Good Parts: This is Douglas Crockford’s book on JavaScript, and it’s brilliant. It’s only 176 pages, but manages to pack a lot into those pages. By the end you’ll know how to write a recursive descent parser for parsing JSON in JavaScript (some really beautiful code).

Move over Java, I have fallen in love with JavaScript: Miško Hevery usually writes great things about testing – here he talks about JavaScript, from the perspective of a Java programmer.

Best resources to learn JavaScript: This is a useful list of resources for learning JavaScript (as suggested by its title).

Structure and Interpretation of Computer Programs: If you still don’t understand what all the fuss is with functional programming, read this book. I’m only half-way through, but it’s already taught me more about programming than any other book. It’s also probably the reason I love JavaScript so much, because deep down, JavaScript is just Scheme in C’s clothing.

Categories: Programming Tags: ,
  1. October 24th, 2015 at 06:14 | #1

    Very shortly this web site will be famous among all blog viewers, due to it’s nice articles

  2. November 4th, 2015 at 04:12 | #2

    I don’t create a comment, however after browsing through some of the responses on Skilldrick Why JavaScript is AWESOME. I do have some questions for you if you do not mind. Is it just me or do a few of these remarks appear like they are left by brain dead folks? :-P And, if you are posting at other sites, I would like to follow you. Would you list of every one of your social networking sites like your twitter feed, Facebook page or linkedin profile?

  3. November 7th, 2015 at 22:06 | #3

    great blog I love playing the irish lottery

  4. November 12th, 2015 at 05:07 | #4

    Joomla mengesankan cukup untk menangani situs yzng sangat sarat dengan konten besar . Bisnis dpat fkkus pada kompetensi inti mereka pada saat yang sama waktu mendapatkan pekerjasn mereka disampaikan pada waktu. pengembangvan perangkat lunak dapat juga disebut sdbagai pengembangan aplikasi, desain peangkat lunak, merancang pengembangyan aplikasi enterprise atau pengembangan aplikasi perangkaqt lunak .

  5. November 12th, 2015 at 10:02 | #5

    I would like to thank you for the efforts you have put in writing this blog. I am hoping to check out the same high-grade content from you later on as well. In fact, your creative writing abilities has inspired me to get my own blog now ;)

  6. November 21st, 2015 at 04:54 | #6

    Its not my first time to pay a visit this web page, i am browsing this website dailly and take nice information from here every day.

  7. November 21st, 2015 at 05:59 | #7

    Undeniably believe that which you stated. Your favorite reason seemed to be on the net the easiest thing to be aware of. I say to you, I certainly get irked while people think about worries that they just do not know about.

    You managed to hit the nail upon the top as well as defined out the whole thing without having side-effects , people could take a signal. Will probably be back to get more. Thanks

  8. November 22nd, 2015 at 07:48 | #8

    I’ve read a few excellent stuff here. Definitely price bookmarking for revisiting. I wonder how much effort you set to create one of these excellent informative site.

  9. November 22nd, 2015 at 17:51 | #9

    Hi there, I discovered your website by the use of Gogle whilst searching forr a related subject, your website got here up, it seems to be great. I’ve bookmarked it in my google bookmarks.

    Hello there, just was alert to your webpog via Google, and found that it’s really informative. I am gonna watch out for brussels. I will be grateful for those who proceed this in future. Lots of other people will be benefited out of your writing. Cheers!

  10. November 23rd, 2015 at 04:10 | #10

    Thanks to my father who informed me concerning this website, this weblog is truly remarkable.

  11. November 23rd, 2015 at 13:02 | #11

    I was very pleased to discover this web site. I want to to thank you for ones time just for this fantastic read!! I definitely savored every little bit of it aand I have you saved as a favorite to look att new things on your website.

Comment pages
1 2 3 321
  1. September 6th, 2010 at 12:02 | #1
  2. October 11th, 2010 at 11:55 | #2
  3. November 9th, 2010 at 11:16 | #3
  4. April 26th, 2011 at 21:14 | #4
  5. July 22nd, 2014 at 12:27 | #5

Comments parsed as Markdown.