Home > Programming > Why JavaScript is AWESOME

Why JavaScript is AWESOME

September 3rd, 2010

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.

  12. December 5th, 2015 at 15:39 | #12

    Beberapa gateway pembayaran yzng paling umjm yang digunakan dalam website ini Pay Pal, Moneybookers, CC Avennue dan suka . Dengan gabungan dari PHP dan LAMP klien endapatkan kegiatan bisnis online mereka .

    Sebuah desain inovatif merebut perhatian maksimum pelanggan sasaran .

  13. December 10th, 2015 at 07:48 | #13

    For latest information you have to go to see internet and on world-wide-web I found this web site as a best web page for most up-to-date updates.

  14. December 12th, 2015 at 08:18 | #14

    This article gives clear idea in favor of the new visitors of blogging, that really how to do running a blog.

  15. January 17th, 2016 at 01:17 | #15

    I am regular visitor, how are you everybody? This paragraph posted at this web site is genuinely nice.

  16. January 27th, 2016 at 12:55 | #16

    This can hurt a lot, cause an injury to the eye and the temporary loss of vision could make you fall off your bike too. For beginners and people who have not ridden their bicycle in a while, it is important to cycle in intervals. But if you have a specialist who can repair them it might be the right fit for you.

  17. February 1st, 2016 at 01:27 | #17

    Watch Deadpool Full Mvie Online: Pretty! This was ann extremely wonderful article. Thanks for supplying these details.

  18. February 11th, 2016 at 13:59 | #18

    I pay a visit daily some sites and websites to read content, however this webpage presents quality based writing.

  19. February 12th, 2016 at 00:36 | #19

    We’re a bunch of volunteers and opening a new scheme in our community. Your website provided us with valuable information to work on. You have performed a formidable process and our whole group will likely be grateful to you.

Comment pages
1 2 3 321
Comments are closed.