The new language was unique in that it was lightweight and directly connected to everything in the browser. The familiarity of C-style syntax, like Java, but no need for applets or a compilation step. All you need is an HTML file with a few syntactic sprinklings. Remember stuff like this?
The second key was that computers and network connections had gotten a whole lot faster. I built my own computer in late 1999, and even with a lot of high-end hardware, it needed dedicated decoder hardware to play DVDs. Moreover, it was unthinkable to download video at the quality of DVD! YouTube first got its start in 2005 - progressing to high-resolution video over the next few years.
It’s useful to consider the time before, when all of this was not a given. When jQuery was a bleeding-edge concept. Because we’ve all grown far too accustomed to this current quite-accidental situation.
The very traits that allowed for ease of use in web pages make it bad for large, high-quality applications. It compiles at load-time, preventing up-front validation. It doesn’t crash in many invalid states, so browsing can continue uninterrupted. With no built-in module system, it works best with code snippets in an HTML file or one external code file.
We do have small bits of modernity sprinkled into the language today, like
use strict and
let but these are opt-in since parsers need to be backward compatible. And so the language is hamstrung by decisions made very long ago.
Here are just a few of the errors we would expect our platform to catch for us:
NaN. Or it might spread through your numeric calculations.
Object.prototype.toString()but other parts of the application probably depend on the standard behavior.
Array.prototype.sort()sorts in-place, so you’ve just modified your caller’s data!
And there’s a whole set of trip-hazards in the syntax itself. There’s nothing to catch here, just certain language constructs which should only be used with extra care:
undefinedare different values
==operator gives really unexpected results. These are all true:
null == undefined,
0 == , and
'' == false
if (variable)means you’re now working with truthiness and falsiness, which has its own confusing set of rules
thisis often not what you expect
Let’s consider a few other alternatives, from large ecosystem to small:
The landscape of web application development is complex enough even without fighting your programming language. Choose one of these and move faster. Immediately erase several classes of bugs!
And that means you still need to consider the standard questions. How much code are you sending down to the client? What is the download, parse and compute time for all that standard library Java code that just got compiled into your package? It’s surprisingly easy to make a mistake here with these new layers of indirection. Put some protection in place.
The other important angle is whether you really need all that code in the first place. How much interactivity do you really need? Are you more like Gmail, which has an explicit load step before you can do anything, or is it more like a blog post or landing page and interactivity needs to be immediate?