JavaScript Sucks

I really know many languages pretty well, but this language is really ugly or stupid or what not. So many features are only “hacks”, browsers do whatever they want with the code differently from each other and there’s chaos about JS everywhere you go.

For example, what we call a ‘dictionary’, which is an associate array is a big hack in the language. It is practically an object which you can set properties, and then iterate over them. There’s no formal way to remove a key from the dictionary, like you would expect in a scripting language; by doing myDict.remove(“key”). You will have to do delete myDict.key. Not mentioning how to know if you have any keys in the dictionary, because who said you have the length property? Well, if you think you have it, then you’re wrong, that’s because you used an array as a dictionary instead of creating an object using { }.

Another thing I encountered was that if you have a dictionary with the last defined element ends with a comma, then the browser (IE) will shout at you while other browsers eat it well. It reminds me the macro’s in C/C++ that you don’t know where’s the originating code which caused the problem, since it gets compiled after it’s substituted… So {a:1,} will kick.

Another ugly thing is this fake OOP, now who are you kidding? Adding a special use for the “this” keyword, but otherwise everything else is just nested function, err sorry, methods. This is another ugly hack, and some people even use inheritance. Do me a favor. The errorprone “class” that you declare will probably have memory leaks, because the methods were really defined as nested rather than using something like MyClassName.prototype.myMethodName, which will certainly work better and not get allocated per instance. Did you say private member? Oh yeah, right. That’s what you think and this time you’re right. Because they are local variables to the “class” which is really a function that gets run when you create an instance. However, you don’t have control over public/readonly, etc, which is pretty much useful. So constructor is free of charge because it’s the code in the “class” function, where you also define the private variables. And I won’t call them private members. Now you say, “of course, there’s no need for a destructor, a scripting language has a GC”. Well, that’s right, but when an element points to code, using onClick for example, and that handler has a variable that points to that same element, then you’re in a circular trouble ;) So this time you might want to have a destructor right? Or having some function that will be called on unload so you can null() a few variables to break the circular references…But yes, this problem might happen in many environments, but Java for the sake of conversation solve this one unlike Python, AFAIK.

Now why the heck browsers need to compile (yes, in a way) code??? We just all grew up into believing that’s something normal, but stop and give it a thought. I guess those guys didn’t hear about standards.

You can even open a new nested block using curly braces, but all the variables you declare there are become globals. So you end up deleting some objects you have to manually. Now don’t start with why you wanna delete a variable, there are good reasons for that sometime and that’s another story.

Did you know about javascript compiler time machine? Ahh of course not, let me show you:

var a = “DEFINED”;

function f() {
 var a = 5;

Will this code snippet open an alert with a text of “DEFINED”? No, now keep on reading.

If you run that code snippet above you will get an exception with “a is undefined”, now the compiler or whatever freak under there sees the a, which is really defined in the global scope, right? Yes, it is, seriously. But then it sees later on that the ‘a’ variable is being defined in the scope of the function ‘f’ and decided to make the first one undefined. Make an experiment and remove the ‘var’ from the definition of the ‘var a = 5;’ and see for yourself the results.

And there are more and more quirks in this language that I will leave for another time. So what do you think, is Silverlight the best next thing?

27 Responses to “JavaScript Sucks”

  1. lorg says:

    1. There are ways to handle reference cycles in python. (Via the gc and weakref modules.)
    2. Regarding local/global variables. The following fails in Python as well:
    In [1]: a = 1
    In [2]: def f():
    …: print a
    …: a = 2
    In [3]: f()
    With an UnboundLocalVariable exception.
    I ran into that one once. Fortunately, it’s pretty rare, and easily solved (Also, not that big a problem in the first place).

  2. bigkif says:

    Seriously, I think you should have read ECMAScript specs before talking about “hacks” in the language.

  3. Mike says:

    JavaScript was great in the old days but as it has evolved it has got very messy and it isn’t pleasant to work with anymore.

  4. Ryan says:

    I agree with a lot of what this article is saying. The language is designed to be a hack of web pages. And i disagree with Mike. JavaScript was *never* pleasant to work with.

  5. Johnny says:

    Just wanted to offer an amen. We need to start anti-javascript conferences so we can compete with all these AJAXian whack-jobs who think js is the next big thing. I don’t even keep up with their lingo. I think they’re all idiots who don’t understand the point of the web.

    I used javascript once. I had to write a thousand python scripts just to get the taste out of my mouth.

  6. Lard Elrund says:

    In my opinion JavaScript is great, but developers make it ugly because they try to make it something that it’s not. The classical-inheritance is one example. JS is simply a different kind of OOP, it’s not class-based, but prototype based for more flexibility and from the supposition that most classes in the code would be instantiated only once anyway.

    So all those that started to build `hacks` around the language have actually contributed to its ugliness. Just use it plainly and with the help of good libraries out there that handle low-level browser issues.

    Here is post I wrote on a similar subject:


  7. Jonny says:

    Stupid developers don’t even realize they want heavy-client architecture again. These flaky bastards can’t help but to act like indecisive ditsy college girls, first it’s thin-client, then heavy-client, then thin-client, now heavy again.

    And yes I agree, why do we need to download source code from across the planet for some lame browser to compile only to screw it up? That’s like ordering a pizza and getting nothing but a bag of flower and directions to a farmer’s market, oh and a note that reads “F*** YOU!” JavaScript was hacked and re-hacked by nine-year-olds high on amphetamines while getting a$$-r@ped by elephants.

  8. Ryan says:

    Boo hoo dickheads. JavaScript IS the next big thing whether you like it or not. prototypical inheritance is vastly superior to cllassical inheritance.

    The only reason JavaScript has remained broken for so long is thanks to Microshaft’s original monopolising efforts and the now the necessity of having full backwards compatibility so as not to “break the web”. That’s not a problem many other languages have to deal with.

  9. Chris West says:

    I am a huge JavaScript enthusiast, but with that said I do partially agree with this post. I agree with the fact that it is very annoying having to worry about how one browser will handle code compared to another. On the other hand, I also agree Lard Elrund who said that many people want JavaScript to be a language that it was never intended to be.

  10. Thomas S says:

    Who cares about ‘breaking the web’ – half the stuff that it would break is probably junk no one uses anyway and it would force the owners to update their code.

    My beef is the lack of a simple ‘include’ statement. How hard is it to allow the capability of a single javascript code stream to be pulled from multiple sources? Even if you require they be local to the top level JS file. Not having include ruins the ability to write modular code as every module you want has to be included in the main document (HTML, SVG, etc), even though the main document has no need to know how the solution is broken up into separately maintained subparts. Or you write one huge file.

    Javascript is like a massive flat-table masquerading as a database in the days of relational databases.

  11. m says:

    It’s not exact fair to criticize a language by the inherent effects of popularity. It’s developed warts. It’s also not fair to blame Javascript for browser differences.

    You’re criticizing language principles that are unique to any prototype dynamic language, of which there are very few.

    You have to understand prototypal programming to “get it”. The idea of a class that exists as a distinct contractual agreement for the behavior of an object (an instance in classical languages) doesn’t make sense in a dynamic languages. C++ had classes as a way to informs the compiler how to graph objects in memory. Some dynamic languages carried over the idea without understanding the premise. Javascript did away with them in favor of prototypal.

    But you need to actually start thinking of inheritance in terms of repurposed mutations of other objects… that’s a big mental hurdle.

  12. Crank says:

    I would totally back up the opinion tha JavaScript is bullshit. Here is why:

    1. It gets transmitted as text, not compiled code, which greatly increases the package size and increases the time needed to JIT it.

    2. It is interpretted, not compiled, which means that even simple errors are always there – you have to test each code path even for typo errors, which is of course impossible. Now that alone makes it junk for something larger than a few hundred lines.

    3. It is probably the worst language around in general – not strongly typed, not object oriented, not compiled – it is not a language – more like a snort-and-grunt kind of think. The guy who invented it should endlessly suffer my curses.

    4. It is not modular, nor versionable – once you all fans of JS start to write JS that integrates in CMSs with other third party JS around, you will see what I am talking about you morons – a complete mess.

    5. There are NONE and never will be ANY quality IDEs for JS – simply because the JS is an interpreted junk. Do you call FireBug development enviroment? – that little crab…

    I myself have writted code at all types of structural languages – from ASM, C, C++, Pascal, C#, Java, but JS is the only one that is real shit in action – you can never write efficent JS – it all goes to variants, which means internal casting everywhere, no stack utilzation, no memory management of any type. Top that with the fact that browsers suck anyway and you have millions of so called “web developers”, getting paid to do bullshit.

    I personally pretty much dispise “web developers”, because to me these are not developers at all – the only thing they know is how to concatenate HTML strings, which also sucks big time.

  13. Crank says:

    So once we all agree that JS is crab, lets see whether Silverlight is the next big thing. It surely is not. Here is why:

    1. Silverlight is developed by a company that has no intention on making it cross platform – so Silverlight will run OK only on Windows, SLOW on Mac and on Linux/Unix/mobile devices it will run SilverDARK.

    2. Even on supported OSs, it is nicely crafted to not perform well. The heavy retained rendering, makes it impossible to run high level of detail scenes (your computer struggles for memory when SilverMemoryMonster is around, and most of the time your computer is busy retaining instead of rendering).

    3. It does not provide integration with the native OS essential features, or even when such are supported (for example the only CLIPBOARD format is TEXT and the only DROP format is file – what about that funny and not so funny joke:)

    4. It does not provide enough input information even when available – try get the currently pressed keys for example.

    5. The new 3D rendering API does not even run on MAC – one of the initial platform Silverlight was intended to run. There are MS speakers that talk about they are thinking of running it on MAC. Now tell me how will you run XNA and XNA shaders on MAC?

    6. The entire SL API is intended to run one thread – whats worse this is the UI thread. So although you can have multiple threads you cannot use them for rendering, because the SL rendering API will throw when accessed from a thread other than the UI thread.

    7. Last but not least is the printing. As with WPF you print a UIElement. Now that alone is stupidity in action – I did not know printers can render clickable buttons. Getting a printer graphics or POST script stream is one thing, but printing UIElement… has this company gone inside, with that new insane leader it has or what:)

    The list goes longer than you can think, as I myself have digged this platform from the guts out. The only real big think for web developement WAS, IS and WILL continue to be JAVA.

    Although I personally preffer the C# language specification over the Java language (I hate the .NET framework), JAVA is the only language+framework solution for portable applications, that have a great chance to run everywhere.

    In fact before the stupid IE broke the Java Applets, we had a much better and powerful web. I am even a little surprised how quickly people somehow forgot Java and what it had to offer, in favor of SL or Flash.

    But listen to me – the developer with 15+ years of professional experience – for now Java has no competition for web/cross-platform development.

  14. Kaboom says:

    Right, Crank, no need for Flash or Silverlight. Next time I need to render some video on a webpage and be able to seek through it, I’ll fire up Eclipse or Netbeans, take a nap while the IDE loads, and…do what exactly?

    Or I can use HTML5 and some, yes, Javascript to take care of it (though I kindof agree with you about JS).

  15. Crank says:

    Kaboom – if you only need to stream a video to the browser – then you can you can use any technology that does the job – you can always later switch the player, because it does not do that much, or at least does not break your web development that much. However videos are not the real problem.

    The real problem is that there is no quaility language+framework for web development and it is impossible to make quality applications that would run inside browsers. This is the real problem – JS as a language is not an option like I explained. HTML 5 is nothing more than more browser compatiblity issues – you cannot fix the absence of a framework by just adding tags.

    That is why the W3C has to concentrate on the inclusion of managed languages inside the browsers, and standartize only hosts for plugins, that execute managed code on the client machine. This will make it possible to deliver incredible, code-driven content over the web.

    In this scenario W3C will have to standartize only the input and output interfaces of that managed plugings, not higher level details such as date pickers – will they look the same in all browsers/OSs?. Hell we cannot control the scrollbars on overflow elements yet and now we have date pickers too…

    The developers need to realize that HTML is an old technology and new tags will not fix its incapability to be functionally extended – it will just make things worse – for both developers, which will have to struggle with more browser differences and for users, which will have to switch browsers like crazy to find the one that can finally display a specific page with reasonable quality.

    For me this is the ultimate web development scenario – since Java is the closest thing to it – I backup my initial statement that for now Java has no competition for web/cross-platform development.

    Yes – Java IDEs are terribly slow, Java does not offer such control like C# (does not have structs for example that allow you to leveragate the stack, has a smaller set of primitive data types, no operator overloading and many other for which I prefer C# as a language) – thats all true.

    Java has a lot of gliches, but it simply has no alternative.

  16. Javascript should just die says:

    First, you take a functional language like lisp, which most people do not understand and do not know how to use effectively. Second, you try to make this language so “powerful”, the syntax now looks somewhat like C. (NOT JAVA)

    Now you got a piece of crap that encourage people to write unreadable and unmaintainable code.

    Don’t get me wrong. I like functional programming language and C separately, but Javascript is the worst of both worlds. I have no idea which idiots could have believed that it was a good idea.

  17. Agreed says:

    I agree JavaScript sucks.

    I’m in the middle of reading two great books on the language:

    1. Professional JavaScript for Web Developers (Zakas)
    2. JavaScript Patterns (Stefanov)

    Both of the books are excellent, so nothing against them or the authors at all; but so far I think it’s an ugly, hacked-up and confusing language. The OO techniques are especially so. I need to get above “intermediate” level for professional reasons, but I’m really not having fun. Give me a strictly typed, proper OO language anyday over this bunch of hacks.

  18. Scurvy Cur says:

    Worst than the JavaScript language itself is the browser environment, where I’ve noticed some operations fail silently on some browsers, or give incorrect results that are undetectable from within JavaScript code.

    You can’t unit test for whether a browser quietly places an element 30 pixels to the right of where you told it to place the element, nor can you unit-test for whether an in-memory Image grows and shrinks when you zoom in and out of a page with Ctrl+Scrollbar. Problems like this mean that, contrary to accepted JS wisdom, you have to explicitly check the host browser’s name and not attempt to programmatically check for browser features.

  19. Tom says:

    Just to clarify:

    6: Afaik no UI framework is capable of modifying the UI from a non UI thread without issues. However, you can use thread marshalling (SL: Dispatcher.BeginInvoke) to update the UI during a background thread process. Best practice is to do it in more small pieces.

    7: You can build up documents from the SL primitives, that will be also an UIElement. Furthermore, SL has PostScript Vector printing API.

  20. James Hancock says:

    All late bound script languages suck.

    They are not discoverable, they’re not syntax checkable, you can’t catch errors at compile and design time, they’re virtually untestable because of no structure, and javascript is just worse than most.

    First law of programming is “Do no magic”. But almost everything is magic in javascript.

    Want an array of classes?

    Sure, go ahead and put them in and name the fields whatever you want, and every element of the array can have a different definition.

    Wow this is so powerful!


    It’s a good way to have typos up your ass, have almost impossible to debug code because you’ll only hit it every once in a blue moon, and you don’t have a class definition that anyone else can work from and understand.

    Then there is the magic inline functions and definitions as a result of this stupid array syntax that lets you define a ton of crap all at once.

    Sorry, but the only thing about this syntax (see the .ajax function on jquery for examples) is that it’s short. But I type 120 words a minute. I could give a damn about short. I want readable code, that is clear what it’s doing, with no magic and no made up stuff that you have to dig into documentation forever to find.

    Oh, and then, because of all of this dynamic late bound CRAP there is no intellisense, so you can’t splunk frameworks at all.

    Oh and then there is 0 intelligent error handling in any functions so it normally crashes in minified (or incredibly complex code written by someone else that you can’t possibly understand because of the magic that is going on) code with no way of knowing WHY.

    Javascript is a step back to the dark ages. I would say that it was a step back to something that I’ve used in the past 30 years, but you know what? There isn’t anything that I’ve ever written in other than maybe Scheme/LISP on unix in a text editor that is as bad and that was for largely the same reasons, but wasn’t nearly as bad because it still required STRUCTURE instead of made up crap.

    And the worst part of this whole thing is that .NET and other real languages are copying this crap and making their languages worse to deal with the mess that is javascript.

    End the madness. Give us a strongly typed, fully bound language for web. If script kiddies copying and pasting want to use this crap, let them. For the rest of us, give us a real language.


  21. Steve says:

    I have a C++ & Java background and I’ve just started learning JavaScript, and after learning the following I had to go out onto the internet and express my disbelief:

    If I have the following function:

    function doSomethingUseful() {

    var customerName = “Bob”;

    // Other stuff ….

    But then decided to change the name like this:

    function doSomethingUseful() {

    var customerName = “Bob”;

    // Other stuff ….
    customerNmae = “Joey”;

    In every other language in the world alarms would go off because my customerNmae misspelling creates a meaningless identifier. But not in JavaScript! Not only have I created a new variable, I’ve created one with GLOBAL SCOPE! Since the language doesn’t provide data types for no known reason, the system knows the variable is the meaningless “var” type.

    I’m seriously reconsidering learning this language because it already seems like a sloppy mess, but I see it so often on employment requests so I feel compelled to learn it. Ugh. It’s like the pig latin of computer languages.

  22. Jonny says:

    The justification almost always given for using JavaScript is the low barrier to entry, read: “I’m lazy and don’t like learning how to build things properly”

    Don’t have a problem with prototypical inheritance, but prototypical inheritance doesn’t need JavaScript.

    The language is a huge fail, my points reflect Crank’s points:

    – There is no compile-time, so simple mistakes (such as a misplaced comma) can take-up to two hours to track down.
    – It’s non-modular, so you have to include source files using HTML “” tags or rely on some proprietary boot-loader that botches your debugging tools.
    – The best IDEs out there (IntelliJ) consistently fall short of the mark and cannot reliably and consistently introspect your source code for large projects involving “JavaScript frameworks”
    – Function.apply (this, […]) makes no sense, a duck is not a dog, and “apply” is a counter-intuitive name for calling a method.
    – Everything is a variant, safe-typing is not allowed, yet more of my time wasted tracking down implicit and incorrect type conversions.
    – hasOwnProperty is a joke

  23. Lothar says:

    I googled for “Javascript sucks” to find arguments for and against it. Unfortunately most i find here are people not willing to learn a different language, not knowing anything about dynamic typed languages and surely none of you have read the language spec at all.

    The only real problem i see is the lack of modularity. But the typical convention of one global variable per library is a first step.

    But i agree. Like all dynamic languages (ruby, php, python) it gives you a 10x performance boost when programming small systems. But this doesn’t scale to large and multiperson projects.

  24. Richard says:

    The next thing better than shit is Javascript. It is the worst language ever in creating web application, and because it is so successful, make it even worst.

    How much more hair Javascript want me to pull from my head ? And I don’t even have hair to begin with !

    enjoy the shit if you want … but i am out. Now aiming for Dart, which has better chance of hitting bulleye.

  25. Dean says:

    It’s a scripting, interpreted language. It’s design, use, and purpose are different than that of C++/Java and it’s a little higher level than either. So it’s kind of not fair to be comparing them together (like mentioning that it’s not compiled by some commentators here). But yeah, there are the annoyances of making use of hacks to emulate certain features of other languages (classes, private members) and that it’s always ugly and therefore difficult to maintain. But I think a lot of hatred comes from people with C++/Java backgounds applying rules from these languages to JS and then getting frustrated. :P I think Elrund puts it best.

  26. Jake says:

    all you people discontent with javascript and weak-typed, whack-ass languages might want to check out Ada..

Leave a Reply