Introduction: JavaScript vs. VBScript
Alot of people ask me whether I think it makes sense to learn VBScript. While I do answer this question in my note, Why VBScript matters, there is one thing I specifically don't cover in that essay: The great JavaScript vs. VBScript debate.

Here's my answer.

For most people, the issue of choosing one scripting language over another is moot: They either don't care one way or the other, are not technically astute enough to make the distinction, or just looking at JavaScript and say, hey, why use anything else? JavaScript works on all browsers.

Fair enough. But I'd put the argument another way: JavaScript is an incredibly difficult language to learn and use correctly. Anyone who tells you otherwise is a Microsoft basher, is a programmer themselves, or is trying to sell you their own JavaScript book (and before you ask, my VBScript book is out of print, so money is not clouding my own thinking on this issue). Because JavaScript is so close to Java, C, C++, Objective C, Perl, and a variety of other languages, one might think that this familiarity will prove to be some sort of advantage. It isn't. As any honest programmer will tell you, these languages are all so similar that the differences will come back and bite you in the butt again and again. In fact, I'd argue that it is JavaScript's similarity to these languages (which are all difficult and hard to learn themselves) that is, in fact, it's biggest weakness.

VBScript, however, does not suffer from this problem. VBScript is identical, syntactically and grammatically, to Visual Basic and Visual Basic for Applications, making it easy to move on to bigger and better things. And because Visual Basic is so easy, anyone can learn it: Visual Basic is the volkslanguage, the language of the people. Embrace it.

And because VBScript is so easy to learn, you'll be able to master things such as HTML, Dynamic HTML, Cascading Style Sheets (CSS), and other Web technologies that much quicker because you won't be bogged down in the language quicksand that is JavaScript. I've never seen a language fight, kicking and screaming, to prevent Web pages from loading like JavaScript does.

Let's face it: JavaScript is a bastardized language. Developed by Netscape engineers as LiveScript, its name was quickly changed to "JavaScript" so that Netscape could feed off of the sucess of Java, like some fish hanging off the belly of a shark. JavaScript has nothing (absolutely nothing) to do with Java: They weren't created by the same people, they weren't created for the same reasons, and they were not created with each other in mind at all.

Don't believe me? Over the next few months, I'm going to begin converting my VBScript examples on this Web site over to JavaScript. No one asked me to do this. And I don't need to learn JavaScript for any particular reason other than the fact that I am a programmer and I have a natural curiosity and desire to learn everything I can about all Web technologies. I don't want you to be like this, you have a life. So consider this a mental exercise: I wanted to see how hard it would be to turn simple VBScript into JavaScript.

As of this writing, I've converted the code from Chapter 1 and Chapter 2 (if you navigate to those pages, you will see links to view the JavaScript versions of those pages). And it's every bit as ugly as I've said.

Here's an example. Consider the following simple VBScript code:

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
  Dim x
  For x = 1 to 10
    document.write x & "<BR>"
  Next
-->
</SCRIPT>

Written in JavaScript, it looks like this:

<SCRIPT LANGUAGE="JavaScript">
<!--
var x;
for(x = 1; x <= 10; x++)
{
  document.write(x + "<BR>");
}
//-->
</SCRIPT>

Not too big of a difference, you say? Hold on: That's not true. There's a huge difference between these too blocks of code. Here are the obvious ones:

  • The keyword var is used to declare a variable name, but you must use the ; character at the end of every line of code. Otherwise, crash.
  • JavaScript is case sensitive. That means you must use var, not Var and for not For, etc. Otherwise, crash. VBScript doesn't care how you write code.
  • What kind of syntax is (x = 1; x <= 10; x++) anyway? It was ugly in C, and it's ugly now when JavaScript rips it off. The VBScript version reads like English. The JavaScript version is, well, awful looking and hard to understand.
  • Don't forget to use brackets (the { and } characters) between blocks of code or JavaScript will choke and crash.
  • The parameters to function calls (such as document.write in the above example) must be surrounded by parenthesis. Otherwise, crash. In VBScript, they're optional.
  • Don't forget the // (double-slash) characters before the end of comment characters (-->) at the end of the script block. Believe it or not, this tells JavaScript that those characters are not part of the script, while the characters its hiding tell the HTML parser that the script is not part of the HTML. No, I'm not making this up. And if you leave them out, JavaScript crashes.
  • JavaScript uses the same character for concatenation as it does for addition (the + character). That's inane for a language that is supposedly syntactically superior to VBScript.
I could go on, but you get the point: This example is one of the most trivial JavaScript code samples around, but it's got all kinds of issues. VBScript, however, is clean and to the point.

There's one more little point here: As a long-time user of VBScript and Visual Basic, I've grown accustomed to the wealth of built-in functions that are supplied by these languages. It has wonderful string functions and date and time functions that just are not available in JavaScript. In working up just the first two chapters in JavaScript, I've run into several areas where VBScript provides built-in functionality that JavaScript just doesn't have. JavaScript "programmers" would have to create this functionality themselves (for a good example, see compare the VBScript and JavaScript versions of my script that displays today's date. The VBScript version is simple and elegant. The JavaScript version is ridiculous).

And with end of 1999 coming upon us, the one previously legitimate excuse for using JavaScript is no longer valid: Netscape Navigator does not represent a significant share of the Web browser market any longer. As I predicted years ago, Internet Explorer is now the defacto browser of choice on the Internet, giving VBScript an overwhelming audience. So there's no reason to use JavaScript, unless you're a die-hard programmer working in UNIX Web shop. And if that's what you're doing, you have my condolences. For the rest of the planet, well, time is too valuable to waste it on the convoluted syntax of JavaScript.

So enjoy yourself. If this stuff gets too hard, it's not fun anymore.

--Paul Thurrott
September 4, 1999


All content © 1997-1999 Paul Thurrott