25

It seems to me that, despite being one of the world's most used languages, even some of the leading experts of JavaScript like Doug Crockford think JavaScript suffers from some pretty big design flaws (JavaScript: The World's Most Misunderstood Programming Language) that make development confusing and ambigious.

Programming languages and development tools are always getting better and make it much easier for developers to make things. There's a new version of .NET every few years, new version of HTML5 with new tags, new versions of CSS, etc.

Why hasn't there been a better version of JavaScript or another dynamic loosely typed language, but without all the design flaws, come out to supercede JavaScript?

6
  • 7
    It's a bit unfair to use Doug Crockford as an argument here, because he's a very vocal fan of JavaScript, at least of the good parts :) And getting rid if the bad parts is, after, all, his job in the ECMA committee.
    – balpha
    Jul 6, 2011 at 14:08
  • 1
    No new version of Javascript? Isn't the Ecmascript 5 spec just two years old?
    – user16764
    Jul 6, 2011 at 17:24
  • 4
    Inertia I guess. I sure wouldn't choose javascript if there was any other reasonable choice. After working with other languages desktop side, going into javascript is like having to go back to FORTRAN or COBOL. Certainly doable, but seems more painful than it should be. Jul 6, 2011 at 19:29
  • Because all the choices that the stodgy types like Brian are more comfortable with couldn't handle the problem. And the problem was big. Don't write to a JVM but instead write to like 6-20 browsers several of which refuse to agree on what your code actually means. JS is powerful and Crockford either understands a lot less about JavaScript than he knows about JavaScript or he's just doing his part to get the old guard to pay for seats at his speaking engagements. Dec 20, 2012 at 6:44
  • Isn't Wasm (webassembly.org) aiming to open up the browser to other languages? Sep 19, 2022 at 13:04

6 Answers 6

22

Two words: "Browser Support". Javascript is interpreted by the web browser, so if we were to use a different client-side scripting language, every browser would have to implement support for it. Obviously some browsers would lag behind others and developers would avoid using the language because only a fraction of their potential users would be able to use their application. So, as you can see, there are considerable economic impediments to using anything other than Javascript (or even a newer version of JavaScript). Actually, at this time, there have been newer "official" versions of JavaScript released. However, the only browser that supports then is Mozilla Firefox.

3
  • 4
    Actually IE tried to start down a path of fixing JS the result was IE 6... Jul 6, 2011 at 14:38
  • Okay, yeah, I've removed that statement.
    – Zhehao Mao
    Jul 6, 2011 at 16:26
  • You forgot to mention that there are newer versions of ECMAScript mainly EcmaScript5 and that's a significant improvement on EcmaScript3 as a language. All modern browsers support it (Apart from Opera :()
    – Raynos
    Jul 9, 2011 at 2:39
14

All languages suffer from design flaws. The flaws in Javascript aren't all that serious. Messy type handling (can be circumvented), False/Null/undef/zero/NaN silliness (can be still grasped), "+" for concatenation (perfectly manageable), semicolon insertion (just be cautious) - nothing critical overall.

On the other hand, the language is incredibly extendable. Unlike in other OO languages where you are stifled by class-based inheritance/extensiblity, in JS you are free to extend/modify an instance of an object on the fly. It has a very friendly learning curve - the entry level is very easy, and there's lots and lots to be explored and learned over time. It's the entry level javascript (and the stupid name) that makes people believe it's a toy language. It is not. The advanced features allow you to modify the syntax, the essence of the language so much, that you adapt it to your needs and then achieve desired results in several simple, straightforward lines of (perfectly clear) new syntax. It works very well both for sequential programming and for event-driven interfaces. It integrates with web environment very well.

...also, what other client-side language would you suggest for WWW? Visual Basic? As long as Javascript is the only widely supported browser-side language, any questions "why people still use it" are quite misplaced.

12
  • 6
    There's nothing wrong with + for concatenation, at least not by itself. It only becomes problematic when you add type coercion into the picture. Jul 6, 2011 at 16:37
  • 1
    I have never been a huge fan of Crockford's assertion that the language is flawed. Sure, type coercion can be problematic if you don't understand that it will occur, but is that a design flaw of the language or simply ignorance on the part of the developer struggling with the difficulties that it can sometimes cause? Again, if you know what you are doing, these "issues" are not really issues. JavaScript is a great language, it's too bad it's taken this long for people to start appreciating it for what it is, instead of what people assume it to me. :) Jul 6, 2011 at 17:35
  • By the way, I wish I could up-vote your answer 10 times - you are spot-on. Jul 6, 2011 at 17:36
  • 14
    @Jason: When the majority of new developers have the same "difficulties" with the same "issues" over and over again, IMO that's when it's safe to call it a language flaw. Jul 6, 2011 at 20:40
  • 1
    @JasonBunting: There's nothing wrong with type coercion in cases where it's clearly and unambiguously going to occur. If a language used $ as a string concatenation operator which was defined as coercing operands to strings, then I would have no problem with it allowing "count=" $ it.count without requiring it.count to be explicitly converted to a string. On the other hand, the fact that one cannot tell whether x+y will coerce either operand to string without knowing the operand types is, IMHO, a sign of dubious design.
    – supercat
    Jul 20, 2014 at 16:10
8

It works, and it's widely supported. The language itself is quite powerful and supports a wide variety of paradigms (functional, OOP, etc.). It also has an built in API to the DOM, making it very easy to manipulate a page - after all, that's what it was designed to do!

Also, libraries like jQuery are making it much easier to code JavaScript without worrying about browser compatibility. Since, until HTML5 becomes mainstream, JavaScript is the only way to dynamically manipulate web pages on the browser side, people are still focused on making it better and easier. And even after HTML5 is broadly accepted, many people will still be using browsers that don't support it. So many companies won't switch because they would lose a large number of customers.

Despite its supposed deficiencies, JavaScript is the only client-side browser language we have, and will have for a while. It's going to be around for a long time.

2
  • 1
    Saying that JavaScript "is also tightly coupled with the DOM" is a stretch - the language itself, in its pure form, couldn't care less about the DOM. That's why it can be used for so many other things than merely DHTML. Too often programmers confuse an API for built-in functionality of a language; that confusion is, in fact, one of the reasons why JavaScript has such a bad reputation. Jul 6, 2011 at 17:32
  • 1
    @Jason That's true, it's not really a tight coupling - JS doesn't require DOM any more than the DOM requires JS. I've edited my answer.
    – Michael K
    Jul 6, 2011 at 17:37
4

I think there's a few reasons.

Backwards compatibility is probably key. When IE had 90%+ market share, it would make sense for alternative browsers (Firefox, Opera) to continue to use JavaScript. It would have been a tougher uphill battle if Firefox came out with something totally different.

It's a standard. There's an overlord out there (ECMA) that says what JavaScript actually is. The web happens to like this kind of thing, especially in revolt to IE being "the bully".

Of course, this doesn't get into the the IE vs. Netscape war that put JavaScript in such a mess.

1
  • Technically, ECMA only defines what ECMAscript actually is. JavasSript itself was defined by Netscape, and now by the Mozilla foundation. Addmittedly in common useage nobody but Mozilla actually claims comformance to specific versions of JavaScript, but instead talk about conformance to specific versions of ECMAScript which is continueing to absorb most of the extentions to the core language. (DOM extentions being out of scope of course). Jul 6, 2011 at 18:30
4

Increasingly, we don't. The popularity of all-inclusive libraries (such as jQuery), as well as languages that compile to JavaScript (such as CoffeeScript) has been steadily growing. Yes, JavaScript is still the language that gets interpreted, but I consider it analogous to writing in C, and compiling to machine code.

That said, there are many people out there who wish to understand JavaScript itself, either for the purpose of improving the previously mentioned libraries and languages (and the use thereof), or because they don't want the overhead of libraries like jQuery.

13
  • 5
    Although you really need to know Javascript to write good JQuery, IMO.
    – Michael K
    Jul 6, 2011 at 14:19
  • 4
    -1 jQuery is a Javascript library. It simply wraps several handy methods into its libraries. With out JS we have no jQuery Jul 6, 2011 at 14:41
  • 3
    @Chad: I think you are taking the comments about JavaScript being "the 'assembler' of the web" too literally; it was merely an analogy. Maybe a bad analogy, but an analogy nonetheless. :) Jul 6, 2011 at 17:39
  • 3
    I like jQuery & I use jQuery. However, this idea that jQuery isn't, somehow, JavaScript, drives me nuts. It's a library built-on and for use-in JavaScript. If you don't know JavaScript, you're not going to be able to exploit the power of the language sufficiently to make jQuery as awesome as it can truly be. Those using jQuery that don't understand how jQuery & JavaScript actually work, and don't know how to extend either of them, are like children playing with letter blocks of the alphabet, not realizing the power those letters have, when combined, to create words which can change our world. Jul 6, 2011 at 17:46
  • 3
    Yes. jQuery is JavaScript. Woo. bored now
    – Ryan Kinal
    Jul 6, 2011 at 18:57
2

While its absolute ubiquity within web browsers and web applications is the root cause of JavaScript sticking around in spite of its not-good parts, that same ubiquity has led to it receiving the attention of some of the best software engineers. The end result is that we get ultra-fast JIT compilers and runtime engines, making JavaScript one of the not the best-performing dynamic languages available.

Also, it's not such a bad language. EVERY language has flaws, and to use any of them well, you need to know their strengths, weaknesses and foibles.

Not the answer you're looking for? Browse other questions tagged or ask your own question.