The woes of trailing commas in IE
If you leave a trailing comma in your JavaScript code, you’re a terrible person. It’s right up there with omitting semicolons as far as I’m concerned.
While fixing some issues on a site in IE7 recently, I was greeted by the familiarly unhelpful error message from Internet Explorer 7 that prompted me to write this.
Error: Expected identifier, string or number
You can see an example below:

What does that tell us? Bugger all in fact, unless you’ve tackled this problem before. It’s really unhelpful, but it’s caused by having a trailing comma inside an array/object/method, like the following:
forms.set_errors(
$form,
response.form_errors || [],
response.field_errors,
);
That right there, that’s not cool. It’ll make Internet Explorer explode.
If you had any consideration you would write something more like:
forms.set_errors(
$form,
response.form_errors || [],
response.field_errors
);
tasty.
You can prevent this problem occuring by using a linter, or you can retroactively go and find the problem-causing lines in your JavaScript using a RegEx pattern such as the following:
,[\s\n]*[^\[\{\w\n\s/\*\"\'\$\#\.\`\:\|\!]
Though this is valid according to ECMAScript 5, it’s another one of those bodged features in Internet Explorer that happens to behave unlike every other browser, so I think it’s best to go for the solution that works for everybody.
That’s about all I’ve got to say, I just wanted to rant about this and how terrible IE7 is.
Related posts
- Adding support for Webmentions
I’ve added Webmention support to the posts on this blog. Webmentions are a method for websites to know that they’ve been linked to (or mentioned) from elsewhere on the web.
- Merge Commits Are Just Noise
Run git log --graph on most team projects and you’ll see the problem. Parallel lines everywhere, merge commits that just say “Merge branch ‘feature/x’ into develop”. None of it useful. It’s noise. (Merges aren’t the only source: an hourly GitHub Action was quietly doing the same to my own history.) I’ve been using a rebase-based workflow for years to avoid this. The history stays linear and the diffs stay readable. This post covers both the argument and the specific branch structure I use for team feature work.
- Baking webmentions into the build
Back in 2022 I added webmention support to this blog. The implementation worked but it was entirely client-side, so the page would load, JS would fire, fetch from webmention.io, and render the results into the DOM. With JS disabled or on a slow connection, the discussion section was just empty. It worked well enough that I didn’t touch it for three years, but the rate-limit situation had been silently catching visitors out and eventually I started pulling at the thread.
Discussion
No interactions yet
Join the conversation
Reply from your own site with a Webmention (how?).
