Active Server - Avoid These 3 Common JavaScript Errors


Just as unterminated conditional statements are a problem in VBScript, so are unterminated functions and conditional statements in JavaScript. For JavaScript, curly braces serve as terminators and should be paired together like so:


  • function myfunction()
  • {
  • }

They're also required for your conditional statements, as shown here:


  • if (x == y) {//your code here}

Another common mistake occurs when capital letters are used when referencing keywords. For example, the following JavaScript code is incorrect:


  • Function x(y)
  • {
  • If (y == 12) {alert('yeah');}
  • }

JavaScript won't recognize the capital F in Function or the capital I in If. The final common mistake is unterminated lines of code. JavaScript uses the semi-colon to terminate lines of code.


While remembering to include these in your code may be a pain, there is one small advantage., JavaScript doesn't require a line continuation character to break apart long lines of code. For example in VBScript, you'd need to use an underscore to wrap this long line of code across two lines, like so:


  • longvariablenumber4 = (lonvariablenumber1 *
  • longvariablenumber2) + longvariablenumber3

You'll notice in the following JavaScript code, the underscore isn't necessary:


  • longvariablenumber4 = (lonvariablenumber1 *
  • longvariablenumber2) + longvariablenumber3;

So, if your JavaScript code isn't functioning properly, check these areas first and you'll probably find the culprit.

Go back