JavaScript is a programming language most commonly used in the web browser, however projects like NodeJS have turned it into a popular server-side language as well.

JavaScript Errors in Internet Explorer? It’s Probably a Comma’s Fault

This is a well known bug/feature in Internet Explorer but I’d like to share it again for the sake of beginners, as well as seasoned programmers who forget about it from time-to-time. If you’re testing JavaScript code that seems to work fine in Firefox, Chrome or Safari but chokes in Internet Explorer, a stray comma is probably to blame. Consider the following code:

(Click to Execute)

    arr = [1, 2, 3];
    for(i = 0, c = arr.length; i < c; i++) {
        alert(arr[i]);
    }

This code is dead simple. We create an array with three elements, iterate through that array with a for loop, and display each value. Nothing complicated, and it should run fine in any browser. Now consider a similar block of code:

(Click to Execute)

    arr = [1, 2, 3, ];
    for(i = 0, c = arr.length; i < c; i++) {
        alert(arr[i]);
    }

Notice the different: in the first block of code the array was defined as [1,2,3]. In the second block it is defined as [1,2,3,] with a trailing comma. Firefox, Chrome, and Safari will produce the same output. Internet Explorer, on the other hand, sees a fourth array member which with a value of undefined. Think about it in the context of a complicated JavaScript application. Accidently adding an extra comma to the end of an object or array can produce errors deep within your code or within the libraries they depend on, such as jQuery or ExtJS.

So remember, when troubleshooting JavaScript errors in Internet Explorer, always check for trailing commas, or use a utility like JSLint to find them for you.

The JavaScript Dollar Sign ($) – What’s It For?

My latest project involves some customized extensions to a WordPress based site.  The designer who outsourced the development to me requested a number of JavaScript-based effects, and though I’m aready familiar with a number of other JavaScript frameworks including Sencha (formerly ExtJS), WordPress ships with jQuery and so that’s the framework that we’ve decided to use.

Ever wonder what the heck the “$” means in jQuery or why it was chosen?  I sure did, and just found a great article explaining it.