Wednesday, March 05, 2003


Source: [Hivelogic]

JScript: The Other White Meat.

If you're ever forced to develop something in ASP, you needen't code in VBScript. Instead, consider JScript. VB fanatics may argue with some of these points, but taken as a whole, the difference is almost incontrovertable.

Contributed by a colleague who wishes to remain nameless, the following notes, for your perusal:

Why JScript in ASP is better than VBScript

  • JScript functions can take a variable number of parameters.
  • JScript has try/catch/finally blocks, which is far better than ON ERROR.
  • JScript can create true custom Objects (although more awkward than Java)
  • JScript arrays have sort(). VBScript arrays, you write your own sort.
  • JScript can use escaped control characters ("\n", "\t", etc.).
  • JScript has many more and better operators, (bitwise, ==, etc.).
  • JScript has two kinds of quotes, so "quoting 'quoted' text" is easy.
  • VBScript needs you to use "Set" to assign certian variables, but not others.
  • JScript arrays are far more elegant than VBArrays.
  • JScript associative arrays are far more elegant than VBScript Dictionarys.
  • JScript has much more and better documentation.
  • There is far more open-source or free JavaScript than VBScript.
  • JScript is similar to many other languages, but VBScript is bizarre.
  • JScript can do everything VBScript can do, even Server.CreateObject().
  • You can call your JScript functions from VBScript transparently.
  • Most editors are much better at highlighting/indenting JScript.
  • It is much easier to dynamically inspect JScript objects.
  • ColdFusion and Flash can use Javascript-like language.
  • JScript makes sense. VBScript is crazy.

The Downsides to JScript

  • JScript is case-sensitive.
  • JScript has no do-while loop.
  • You have to convert things sometimes from ASP
  • Pure JScript objects don't save well to ASP's Session, but saving more than 1 or 2 simple things to Session is a bad idea anyway.
  • VBScript-oriented values:
    var JScriptString = ''+vbString; // convert a VBS string
    var JScriptArr = vbArr.toArray(); // convert a VBS Array
    var colLen = vbArr.ubound(1)+1; // use if vbArr is multi-dimensional
    var rowLen = vbArr.ubound(2)+1; // use if vbArr is multi-dimensional

How To, Then?

To use JScript in ASP:

<script language="JScript" runAt="server">

By Dan Benjamin hivelogic@hotmail.com.
6:41:57 PM    trackback []     Articulate []