Python, Firefox programming and Irish Whiskey.

Monday, January 18, 2010

The most annoying thing about javascript

First some background:

Would you believe that the beast above is a valid javascript construct? Those two commas are translated into , undefined , , so the a.length==6 and a[1]==undefined. I would really like to see an example of a code where this construct is helpful. But that's not something we cannot live with. Here comes the winner: The most annoying thing about javascript:

Here we have hit into one of those browser incompatibilities. Firefox, Google Chrome and Opera 9.63 say, quite logically, that len(a)==1. MSIE 7 on the other hand things the array is 2 elements long. I suspect MSIE is closer to ECMA script then others because being struct by the fact that a variation of this example worked in Firefox but didn't work in MSIE I read relevant part of EMCA script standard.

Why is it annoying? In Python I happily jumped at the possibility to generate lists with a comma at the end. How natural, no special handling of the last element. In languages that do not support this I at least get a syntax error. Not in javascript. If I want my code to run in MSIE too (and this stupid comma should be no reason not to) I have to remember this little thing and write more complex code. The worst thing is I cannot even bitch about stupid MSIE, because I believe MSIE has got it right according to standard. Illogical, stupid, but correct.

What is your candidate for the most annoying thing about javascript?