Thursday, March 26, 2009

Beware trailing commas in Javascript objects

When working on web apps, I usually spend most of my time in Firefox, mostly due to the excellent Firebug tool. I've found that as I chop and change code, I might end up leaving a trailing comma in a javascript object declaration:

var someObject={ something: 1, other: "2", more: ["three"], };

Note the comma after the "more" property. Firefox is totally fine with this. IE throws an error, but depending on how your code is structured, oftentimes a hard to trace error.

No comments: