ASP: VBScript vs. JScript
22-Mar-06
The fight is on!
No, ok, really it's not. I have yet to find many ASP developers who use server side JScript. Which sucks for them, because, you guessed it, VBScript is just about the most horrific language to work with if you actually want to do anything other than spit something out onto a page.
Ok, maybe that's a bit harsh. Let's just say I don't really enjoy working with VBScript (or VB, for that matter). I'll let you come to your agreements with your VB-loving self.
I do have a point. Stick with me. (Ever notice I say that a lot? Most people think it's the ADD. Me, I think it's the ADD, to hell with what everyone else thinks. Though it could just be senility. Or Mad Cow.)
Anyhow.
One of the cooler things about (classic) ASP is the ability to utilize multiple languages within a single page. Which means you can write classes and shtuff in JScript, include them (or inline them), and use VB in the body of the page, calling the classes, functions, and variables you wrote in JScript from the VB portion of the pages. Once of the interesting things about doing this (and, actually, a rather large caveat) is that all the JScript on the page is executed first, then the page is handed off the VB engine.
Why's that interesting? Well, imagine you have a simple page like so:
-
<html>
-
<head>
-
<title>Fun with ASP, JScript and VBScript</title>
-
</head>
-
<body>
-
<%
-
myNumber = 5
-
Response.Write( "<!-- Hello from the land of the Ebil VBScript -->" )
-
%>
-
-
<script language="javascript" runat="server">
-
myNumber = 10;
-
Response.Write( "< !" + "--Hello from the land of the Server Side Javascript --" + ">" );
-
</script>
-
-
The value of myNumber is: <%= myNumber %>
-
</body>
-
</html>
(Note that wordpress seems to want to sanitize my code above - there are some additional spaces on some of the server side tags)
So, what do you think the value of myNumber is when it gets spit out to the page? If you payed attention above, you'll get it right.
That's right. The value of myNumber is 5.
Try executing that on a Windows server somewhere. Or you can view the output here. You'll note that the JScript comment is right at the top of the page output (view source, baby), not inline in the page as the VBScript comment is.
Eeenteresting.
Stay tuned. I'll be back tomorrow with some of the ways this can be uber useful.




