Internet Explorer is still a very used browser and VBScript on some of them is the scripting engine of choice.
However it seems like Microsoft decided that it was time to give the good old VBScript a rest.
In this post I will give you a basic comparison of VBScript and Javascript so you can use it as a guide when upgrading your web pages.
VBScript is case-insensitive, and I think this is one of the things you will miss more and probably one of the hardest things to manually fix. Why? Well because in VBScript you could write myVar, MyVar, MyvaR and MYVAR (yes you can even yell in VBScript) and that is no problem at all. However in Javascript each of those is a completely different variable. So making sure that all variable and function names and consistent in all your codebase is probably going to require some patience.
In VBScript you have subroutines (which do not return a value) and functions (that return a value). In Javascript you only have functions. But this is not going to be much of a problem
In VBScript comments start with an apostrophe ' or with the REM keyword. Everything after the apostrophe or REM till the end of the line is a comment. There are no multi line comments. In Javascript you start your single-line comments with // and you can have multi line comments, starting with /* and ending with */
VBScript has only one data type called Variant and you are gonna miss it :( a variant can have several subtypes:
Types are a little different in Javascript. In Javascript unassigned values belong to the undefined data type which is more or less the VBScript Empty object. So when you assigned Nothing in VBScript you will now assign undefined.
Javascript has 7 basic data types
You can use the typeof operator to see the type stored in a variable.
Another thing you will miss from VBScript. Error handling. In VBScript we had the Err object. You could call the Err.Clear to reset the exception indicator. You could just use the On Error Resume Next, meaning that if an error happened your code just continue running and you could eventually check the Err.Number or Err.Description to look for errors.
Well that is gone. Javascript uses the try...catch pattern which works well but it not as syntactically nice as it was on VBScript. On the catch block you get an Exception object and it will have a message property.
Well arrays are almost the same, I think that main difference is that you used indexes line (index) and now the syntax is [index] but in general they are pretty similar.
In Javascript these functions could be mapped to Javascript libraries like moment.js
Almost all have an equivalent on the Math object
RegExp("^[\s]+"),
"")
RegExp("[\s]+$"),
"")Well this is just a shallow comparison between VBScript and Javascript. For those hitchhikers to end of the galaxy on this voyage, remember:
Don't Panic
Time is an illusion. Lunchtime doubly so