JavaScript quick fix


Although statistics shows that in past few years Internet Explorer is getting less and less used, many business applications are run mainly or even exclusively in Internet Explorer. Unlike other browsers, there is a strong tendency to retain use of old versions like IE7 and IE8 (2,8%). Debugging application in IE can be very painful job especially when other browsers like Mozilla Firefox and Google Chrome don’t reproduce those errors. Here are a few tips to avoid frequent causes of IE errors:

1. Create regex /((\,\s*[\}\)\]\,])|((\;|\,)\s*(\,|\;)))/g

Note: To explain previously mentioned regex use site.

This regex looks for some common JavaScript mistakes and misplaced syntax like comma appears before opened parentheses ( “,)” ), square brackets (“,]” ), curly brackets (“,}”  ), before semicolon (“,;” ), two commas ( “,,” )  and all combination of comma and semicolon appearance.

2. Search whole JavaScript code with ((\,\s*[\}\)\]\,])|((\;|\,)\s*(\,|\;))) regex using for example Eclipse development environment: 

3. After search has been finished examine the search results:

Where these regex can help?

  • In complex structures like in DataTable initialization with:
    "bJQueryUI" : true,
    "bInfo" : true,
    "aaSorting": [[1, 'asc']],
    "sDom" : '<"H"Tf>t<"F"lip>',
    "oTableTools": {
       "aButtons": [ "copy", "print",{
                "sExtends":    "collection", "sButtonText": "Save", "aButtons":    [ "csv", "xls", "pdf" ]
   "aoColumnDefs" : [ { "bSortable" : false, "aTargets" : [ 4 ],  } ]
  • Misplaced comma between array elements:
var someArray = [1,2,,3]; 
  • Misplaced comma in function call:
callThisFunction( arg0, arg1, arg2,,argN));

Important: This regex search will match regex used in code so you need to examine search result to eliminate regexes that match because they are not errors.

4. Site can also be used to check your code:

This process won’t solve all your JavaScript errors but it will help you to eliminate some of errors that are hard to see and can be a good starting point in debugging your code.