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?

Thomas Owens
  • 85,641
  • 18
  • 207
  • 307
RoboShop
  • 2,850

6 Answers6

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.

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.

SF.
  • 5,236
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.

Michael K
  • 15,659
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.

Jeremy
  • 4,791
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.

Ryan Kinal
  • 1,491
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.