Posts /

Are you good at Javascript? #1

Twitter Facebook Google+
15 Dec 2009

javascript

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:

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.


Twitter Facebook Google+