Are you good at Javascript? #1

I’m not, really. Still I’ve been debugging some JS code just to remember why I was not so excited in the past about the language: your code needs to cope with browser specific crap.
Now, are you good at Javascript? If so, without running it, have a look at the following code:
var array = [
{
key : 'value',
foo : 'bar'
},
{
key : 'eulav',
foo : 'rab'
},
];
for (var i = 0 ; i < array.length ; i++)
{
console.log ("key -> " + array[i].key);
console.log ("foo -> " + array[i].foo);
}
How many elements does the array variable holds?
That code actually hides an Evil™ syntax detail I discovered today. Now, since I’ve been recently approached by the viral ideas of somebody, I felt compelled to fully understand the above code (and the bug we worked together from which this example came out). So if you really want some hints about what the hell is this all about:
- if you’re not running Microsoft IE7, chances are you’re not going to see anything weird in the console output
- section 11.1.4 of the ECMAScript v3 spec tells you all you need to know about the array initializers
After all, I’ll be probably continuing to study this “suddenly-a-hot-chick” Javascript thing, hoping to find a better world where my eventual code will be living into than that I found in the old days.
| Print article | This entry was posted by Carlo Sciolla on December 15, 2009 at 4:34 pm, and is filed under Developer, Javascript, Sourcesense. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |












