JavaScript is classic worse-is-better.
Turns out that brain dead code distribution was the most important thing. Similarly, brain dead web app deployment is what makes PHP so popular. Seems that when the web was born, "is available in some browsers" was better than "soon to be available in some browsers" and so JavaScript took off like a rocket. JavaScript doesn't get code distribution anywhere close to "the right thing", but it does it and it's ubiquitous, which is what's important if you want to reach people. After that, it's just a virtuous/vicious cycle.